OpenCSV创建.csv文件的位置?

时间:2014-11-18 19:52:26

标签: java android eclipse directory opencsv

我正在使用Eclipse中的opencsv librarie,当我在.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) {}

1 个答案:

答案 0 :(得分:0)

可以在“/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) {
        }