简体   繁体   English

创建一个新文件,然后写入它

[英]Creating a new file, then writing to it

I am trying to create a new CSV file then write to it, the code gets to as far as the BufferedWriter then I get a java.io.FileNotFoundException: /mnt/sdcard/SMSMonitor/04-07-2011/Backup_20:43:00.csv (Invalid argument) exception. I am trying to create a new CSV file then write to it, the code gets to as far as the BufferedWriter then I get a java.io.FileNotFoundException: /mnt/sdcard/SMSMonitor/04-07-2011/Backup_20:43:00.csv (Invalid argument)异常。 Does anyone know why this is happening?有谁知道为什么会这样?

public void generateCSVFile(ArrayList<String> list)
{
    File CreateDirectory  = new File(Environment.getExternalStorageDirectory()
        + "/SMSMonitor/" + subFolderName);
    CreateDirectory.mkdirs();

    try 
    {
        File file = new File(CreateDirectory +"/"+ fileName);

        BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        writer.write("ID, Date, Address, Body");
        writer.newLine();
        for (String s : list)
        {
            writer.write(s);
            writer.newLine();
        }
        writer.newLine();
        writer.flush();
        writer.close();
    }
    catch (IOException e) 
    {
        e.printStackTrace();
    }
}

Try create the file without any colons, as the file system used has it reserved.尝试创建不带任何冒号的文件,因为使用的文件系统已保留它。

See http://en.wikipedia.org/wiki/File_Allocation_Table#Directory_tablehttp://en.wikipedia.org/wiki/File_Allocation_Table#Directory_table

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM