我让这段代码写在sdcard上,现在我怎样才能将它转换为写入内部存储器?
//private String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/liste.txt"; Path used to write on sdcard
try{
File file = new File(path);
BufferedWriter bw = new BufferedWriter(new FileWriter(file,true));
bw.write("something");
bw.flush();
bw.close();
catch(Exception e) {...}
答案 0 :(得分:1)
在android中,每个应用程序在/data/data/package/
此dir只能由您的应用访问,如果设备已植根,则根
要访问此目录并对其进行读/写,您可以使用:
getApplicationContext().openFileOutput(name, mode);
和
getApplicationContext().openFileInput(name);
有关此内容的更多信息:Docs
答案 1 :(得分:0)
使用此代码:
FileOutputStream fos;
fos = context.openFileOutput(FILENAME, Context.MODE_WORLD_READABLE);
fos.write(data.getBytes()); //write to application top level directory for immediate sending
fos.close();
答案 2 :(得分:0)
try{
File file = new File("/data/data/com.example.packagename/files/");
BufferedWriter bw = new BufferedWriter(new FileWriter(file,true));
bw.write("something");
bw.flush();
bw.close();
catch(Exception e) {...}
或
//To read file from internal phone memory
//get your application context:
Context context = getApplicationContext();
filePath = context.getFilesDir().getAbsolutePath();
File file = new File(filePath);