【发布时间】:2017-04-02 15:11:02
【问题描述】:
我想将.pdf 文件和.jpg 文件移动到特定文件夹,然后将特定位置路径保存到数据库。到目前为止,在谷歌的帮助下,我可以将文件复制到新位置(不移动)并将新路径保存到数据库,如下面的代码集所示。
try {
JFileChooser choose = new JFileChooser();
choose.showOpenDialog(null);
File f = choose.getSelectedFile();
File sourceFile = new File(f.getAbsolutePath());
File destinationFile = new File("D:\\" + sourceFile.getName());
FileInputStream fileInputStream = new FileInputStream(sourceFile);
FileOutputStream fileOutputStream = new FileOutputStream(destinationFile);
int bufferSize;
byte[] bufffer = new byte[512];
while ((bufferSize = fileInputStream.read(bufffer)) > 0) {
fileOutputStream.write(bufffer, 0, bufferSize);
}
fileInputStream.close();
fileOutputStream.close();
}
catch (Exception e){
e.printStackTrace();
}
我想知道的是
- 如何移动具有唯一名称的文件而不是复制..?
- 如何显示该文件是否已成功移动的消息
或不在 JOptionpane 中(因为只有我可以插入
部分)..?
- 如何检索那些图像链接以直接打开(如'click 此处打开报告'),它应该在计算机默认打开 图片查看器或 PDF 查看器
请帮助我厌倦了谷歌搜索两个半星期。谢谢大家
【问题讨论】:
标签: java file file-copying