我正在尝试在我的HTC One上写入输出文件,并在LogCat中获得以下消息:
11-21 08: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();
}
我希望有人能够帮忙确认问题所在。