我在Eclipse中使用opencsv库,当我在.csv中编写内容时,我不知道是在哪个文件夹中创建的。我应该说我需要在关闭应用程序时不删除.csv文件,以便我可以存储在 assets 文件夹中,对吧?
我的代码是这样的:
try {
String csv = "data.csv";
CSVWriter writer = new CSVWriter(new FileWriter(csv));
//Create record
String [] record = "hello,world".split(",");
//Write the record to file
writer.writeNext(record);
//close the writer
writer.close();
} catch (IOException e) {}
也许你可以在"/data/data/your_project_package_structure/files/data.csv"找到它的文件
仍然找不到 你可以这样做。 file.getAbsolutePath() 为您提供了完整的路径,您可以确定文件的存储位置:
try
{
File file = new File("data.csv");
// creates the file of name data.csv
file.createNewFile();
//you can print absolute path of file
System.out.println(file.getAbsolutePath());
// creates a FileWriter Object
FileWriter writer = new FileWriter(file);
//pass to csv writer
CSVWriter writer = new CSVWriter(new FileWriter(csv));
//Create record
String [] record = "hello,world".split(",");
//Write the record to file
writer.writeNext(record);
//close the writer
writer.close();
} catch (IOException e) {
}