Android 安卓:如何写入内存

Android 安卓:如何写入内存,android,io,Android,Io,我把这段代码写在SD卡上,现在我怎样才能把它转换成内存呢 //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 FileWrit

我把这段代码写在SD卡上,现在我怎样才能把它转换成内存呢

//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) {...}
使用此代码:

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();
使用此代码:

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();


在android中,每个应用程序在
/data/data/package/

此目录仅可由应用程序和根目录访问(如果设备为根目录)

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

getApplicationContext().openFileOutput(name, mode);


这里有更多信息:

在android中,每个应用程序在
/data/data/package/

此目录仅可由应用程序和根目录访问(如果设备为根目录)

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

getApplicationContext().openFileOutput(name, mode);


这里有更多信息:

如果我的设备没有根目录,我可以使用getApplicationContext()访问根目录吗?不可以,如果你的设备有根目录,你可以使用process builder执行根目录任务!FileOutputStream fOut=openFileOutput(“samplefile.txt”,Context.MODE\u APPEND);OutputStreamWriter osw=新的OutputStreamWriter(fOut);写一些东西;但是我不知道它写在哪里是的,它可以工作并且被写入/data/data/yourpackage/files目录如果我的设备没有根目录,我可以用getApplicationContext()访问根目录吗?不,你不能,如果你的设备有根目录,你可以使用process builder来执行根目录任务,尽管如此!FileOutputStream fOut=openFileOutput(“samplefile.txt”,Context.MODE\u APPEND);OutputStreamWriter osw=新的OutputStreamWriter(fOut);写一些东西;但是我不知道它写在哪里是的,它可以工作,并且被写入/data/data/yourpackage/files目录
getApplicationContext().openFileInput(name);