[英]saving file using JFileChooser at any location
你好,我正在尝试将文件保存在Jfilechooser指定的位置,现在的情况是,当用户单击“保存”时,将在项目方向上以名称标题创建文件,但是我需要给用户选择保存文件的位置,并且使用JFileChooser选择他喜欢的名称
if(buttonPressed.equals(save)){
File myFile = new File("title");
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(null);
fc.setSelectedFile(myFile);
if (returnVal == JFileChooser.APPROVE_OPTION) {
try (PrintWriter writer = new PrintWriter(myFile)) {
for (int i =0 ; i< cModel.getRowCount(); i++)
{
sData.add(cModel.getValueAt(i, 1).toString());
eData.add(cModel.getValueAt(i, 2).toString());
tData.add(cModel.getValueAt(i, 3).toString());
writer.println(i+1 + "\n");
writer.println(sData.get(i)+" --> " + eData.get(i));
writer.println(tData.get(i));
writer.println("\n");
}
}catch(FileNotFoundException ioEx){
}
}
}
尝试
JFrame choose = new JFrame();
choose.setTitle("Save To ...");
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(choose);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.