簡體   English   中英

使用Java創建新的CSV文件

[英]Create a new CSV file using Java

我必須創建一個新的CSV文件並將數據寫入該文件。 這是我的代碼段

String path = "D:\\cradius-data-local\\files\\webapps\\vcm";
String javaPath = path.replace("\\", "/");
String tempFolderPath = "zips"+File.separator+dto.getFileName();
File csvFile = null;
CSVWriter csvWriter = null;
csvFile = new File(javaPath+File.separator+tempFolderPath+File.separator+dto.getFileName()+".csv");
if(!csvFile.getParentFile().exists()){
    csvFile.getParentFile().mkdirs();
}
csvWriter = new CSVWriter(new FileWriter(csvFile), ',');

但是,當我嘗試執行以上代碼時,出現以下錯誤

java.io.IOException: The system cannot find the path specified

我要創建新的csv文件的位置是

javaPath+File.separator+tempFolderPath+File.separator+dto.getFileName()+".csv"

哪個評估

D:/cradius-data-local/files/webapps/vcm\ocr_zips\AMIT_COOL_123\AMIT_COOL_123.csv

正如鮑里斯(Boris)在評論中所寫,您可以讓Java為您完成工作。 考慮以下代碼段:

String path = "D:\\cradius-data-local\\files\\webapps\\vcm";
File file = Paths.get(path, "zips", dto.getFileName() + ".csv").toFile();

用這個:
字符串javaPath = path.replace(“ \\\\”,“ \\”); //創建一個新變量
代替:
字符串javaPath = path.replace(“ \\\\”,“ /”); //創建一個新變量

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM