可能重复:
Android 写入 sd 卡文件夹
使用此代码编写文件:
public void writeFile(String data){
try { // catches IOException below
final String TESTSTRING = new String(data+"-");
String path=Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/test.txt";
FileOutputStream fOut = openFileOutput(path,
MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
// Write the string to the file
osw.write(TESTSTRING);
/* ensure that everything is
* really written out and close */
osw.flush();
osw.close();
}catch (Exception e) {
e.printStackTrace();
}
}
以上代码产生的错误:
java.lang.IllegalArgumentException: File /sdcard/test.txt contains a path separator
我找不到这段代码有什么问题。