[英]Exporting JTable to csv FileNotFoundException
I've got an issue where I'm using the code found here https://sites.google.com/site/teachmemrxymon/java/export-records-from-jtable-to-ms-excel 我使用我在这里找到的代码时遇到了一个问题https://sites.google.com/site/teachmemrxymon/java/export-records-from-jtable-to-ms-excel
However when running the code it throws up the exception: java.io.FileNotFoundException: /home/david\\test.csv (Permission denied) 但是,在运行代码时,它将引发异常:java.io.FileNotFoundException:/home/david\\test.csv(权限被拒绝)
Straight away I can see that there's an issue as it looks to use Windows formatting of file paths rather than Linux. 立刻,我发现使用Windows格式的文件路径而不是Linux格式时出现了问题。
Is there a way I can change this? 有办法改变吗?
The code I have is as follows: 我的代码如下:
private void saveBike1LapActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser bike1FileChooser = new JFileChooser();
int option = bike1FileChooser.showSaveDialog(TrackerWindow.this);
if(option == JFileChooser.APPROVE_OPTION){
String filename = bike1FileChooser.getSelectedFile().getName();
String path = bike1FileChooser.getSelectedFile().getParentFile().getPath();
int len = filename.length();
String ext = "";
String file;
if(len > 4){
ext = filename.substring(len-4, len);
}
if(ext.equals(".csv")){
file = path + "\\" + filename;
}
else{
file = path + "\\" + filename + ".csv";
}
exportBikeLapTimes(bike1LapTimes, new File(file));
}
}
Any help would be greatly appreciated. 任何帮助将不胜感激。
Found the answer, I changed the code to the following: 找到答案,我将代码更改为以下内容:
private void saveBike1LapActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser bike1FileChooser = new JFileChooser();
int option = bike1FileChooser.showSaveDialog(TrackerWindow.this);
if(option == JFileChooser.APPROVE_OPTION){
String filename = bike1FileChooser.getSelectedFile().getName();
String path = bike1FileChooser.getSelectedFile().getPath();
int len = filename.length();
String ext = "";
String file;
if(len > 4){
ext = filename.substring(len-4, len);
}
if(ext.equals(".csv")){
file = path;
}
else{
file = path + ".csv";
}
exportBikeLapTimes(bike1LapTimes, new File(file));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.