我正在尝试创建一个新的CSV文件然后写入它,代码到达BufferedWriter
然后我得到java.io.FileNotFoundException: /mnt/sdcard/SMSMonitor/04-07-2011/Backup_20:43:00.csv (Invalid argument)
异常。有谁知道为什么会这样?
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();
}
}
答案 0 :(得分:6)
尝试创建没有任何冒号的文件,因为使用的文件系统已保留它。
请参阅http://en.wikipedia.org/wiki/File_Allocation_Table#Directory_table