【发布时间】:2012-06-10 00:36:54
【问题描述】:
我在 SD 卡上创建文本文件以附加到要通过 gmail 应用程序发送的电子邮件时遇到问题。 当附加到 gmail 应用程序中的电子邮件时,该电子邮件将永远处于红色的“正在发送...”状态。该文件是使用下面的 createCSVfile() 创建的。
调试我的代码,在不同时间启动我的应用程序,csv_file.exists() 总是返回 false,就好像该文件未找到并且每次运行应用程序时都会创建一样。 但是,使用文件管理器我可以看到文件在运行之间和运行期间存在。
有什么帮助吗? 谢谢
File csv_file = null;
String createCSVfile() {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
csv_file = new File( getExternalFilesDir(null) + File.separator + "InOutStats.txt");
if (csv_file != null ) {
if( csv_file.exists() ){
Log.v("CSV_FILE", "Stat file " + csv_file.toString() +" already there!");
}else{
csv_file.getParentFile().mkdirs();
try {
boolean bool = csv_file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileWriter fWriter = null;
try {
fWriter = new FileWriter(csv_file);
} catch (IOException e) {
e.printStackTrace();
}
BufferedWriter writer = new BufferedWriter(fWriter);
try {
writer.write("Some text here!!! " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()));
writer.newLine();
} catch (IOException e) {
e.printStackTrace();
}
try {
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}else{
Log.v("CSV_FILE", "NO SD CARD HERE???");
}
return csv_file.toString();
}
【问题讨论】:
标签: android android-sdcard fileinfo