我正在使用此代码:
File myDir = new File(getApplicationContext().getFilesDir().getAbsolutePath());
try {
Log.i("CSV Testing ", "CSV file creating");
FileWriter fw = new FileWriter(myDir + "/myfile.csv");
//
// write data to file
//
Log.i("CSV Testing ", "CSV file created and your data has been saved");
// Process for sending email with CSV file
File CSVFile = new File(myDir,"myfile.csv");
// And sending it with email attachment
} catch (IOException e) {
Log.i("ExportCSV Exception", e.toString());
}
但它将myfile.csv作为空白文件发送。我从文件资源管理器中检查了它,其中myfile.csv不是空白并包含正确的数据。我该如何解决这个问题?
我的Logcat消息是
I/CSV Testing (16920): CSV file creating
I/CSV Testing (16920): CSV file created and your data has been saved
I/CSV FILE(16920): CSV file exists
I/SEND EMAIL TESTING(16920): Email sending
D/dalvikvm(16920): GC freed 2902 objects / 186576 bytes in 156ms
I/ActivityManager( 60): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) }
W/ActivityManager( 60): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=android.intent.action.CHOOSER flg=0x800000 cmp=android/com.android.internal.app.ChooserActivity (has extras) }
I/ActivityManager( 60): Displayed activity com.android.email/.activity.MessageCompose: 1156 ms (total 2117 ms)
W/InputManagerService( 60): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@43cf3050 (uid=10023 pid=207)
W/IInputConnectionWrapper( 207): showStatusIcon on inactive InputConnection
答案 0 :(得分:1)
如果确实如此......
你的路径2文件必须在某处丢失,意味着你的路径2文件必须是不正确的....
和bcoz ....
语句File CSVFile = new File(myDir,"myfile.csv");
必须在该位置创建新的空文件..