当前位置: 动力学知识库 > 问答 > 编程问答 >

io - Android : How to write into internal memory

问题描述:

I made this code to write on a sdcard, now how can I transform it to write into the internal memory ?

//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) {...}

网友答案:

In android each application has its own folder under /data/data/package/

this dir is only accessable by your app and the root if the device is rooted

to access this dir and read/write to it, you can use:

getApplicationContext().openFileOutput(name, mode);

and

getApplicationContext().openFileInput(name);

more about this here : Docs

网友答案:

USe this code:

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();
网友答案:
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) {...}

or

//To read file from internal phone memory
//get your application context:
Context context = getApplicationContext(); 

filePath = context.getFilesDir().getAbsolutePath();
File file = new File(filePath);
分享给朋友:
您可能感兴趣的文章:
随机阅读: