1

我把这段代码写在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) {...}
4

3 回答 3

1

在android中,每个应用程序都有自己的文件夹/data/data/package/

如果设备已植根,则此目录只能由您的应用和根访问

要访问此目录并对其进行读/写,您可以使用:

getApplicationContext().openFileOutput(name, mode);

getApplicationContext().openFileInput(name);

更多关于这里的信息:文档

于 2013-02-02T10:11:40.417 回答
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();
于 2013-02-02T10:08:51.220 回答
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);
于 2013-02-02T10:09:07.737 回答