我試圖寫一個輸出文件在我的HTC One和在logcat中得到以下信息:拋出:IllegalArgumentException:文件包含路徑分隔符的Android
8月11日至21日:05:18.228:W /System.err(6609):java.lang.IllegalArgumentException異常:文件/storage/emulated/0/com.example.pattern1/myfile.txt包含路徑分隔
的源代碼在下面給出:
protected void writeToFile(String string){
File patternDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/com.example.pattern1/myfile.txt");
patternDirectory.mkdirs();
FileOutputStream outputStream;
try {
outputStream = openFileOutput(patternDirectory.getAbsolutePath().toString(), Context.MODE_APPEND);
outputStream.write(string.getBytes());
TextView t = (TextView)findViewById(R.id.bottomMidText);
t.setText(patternDirectory.getAbsolutePath().toString());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
如果有人能幫助識別問題,我將不勝感激。
【JAVA的可能重複.lang.IllegalArgumentException:包含路徑分隔符](http://stackoverflow.com/questions/5963535/java-lang-illegalargumentexception-contains-a-path-separator) – timrau 2014-11-21 03:17:09
@Talal Saleem哪條線給你錯誤? – 2014-11-21 03:19:43
@timrau你的鏈接是輸入案例,這是關於輸出。輕微,我知道。 – 2016-10-26 19:33:32