0
동적으로 txt 파일에 쓰려고합니다. 파일 1 줄을 만들고 쓸 수 있습니다. 그 후 두 번째 줄을 쓰고 싶습니다. 아래 코드에서 파일이 존재하는지 확인합니다. 파일이 이미 존재하는 경우 새 파일을 만들지 않고 파일에 씁니다 (아래 코드 참조). 그러나 내가 시도하고 두 번째로 쓸 때마다이 오류가 발생합니다.Android에서 동적으로 txt 파일 업데이트
오류 :
.IllegalArgumentException: File //sdcard//uiu_error_report.txt contains a path separator
코드 :이 작업을 수행하는
String filename = "/sdcard/uiu_error_report.txt";
File myFile = new File(filename);
if (myFile.createNewFile()) {
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append("[" + dateFormatted + "," + module2 + "," + type2 + "," + message2 + "]");
myOutWriter.close();
fOut.close();
} else {
try {
OutputStreamWriter out = new OutputStreamWriter(context.openFileOutput(filename,countFileRows()+1));
// write the contents on mySettings to the file
out.write("[" + dateFormatted + "," + module2 + "," + type2 + "," + message2 + "]");
// close the file
out.close();
// Do something if an IOException occurs.
} catch (java.io.IOException e) {
}
}
어쩌면이를 참조하십시오 http://stackoverflow.com/questions/5963535/java-lang-illegalargumentexception-a-path-separator –