Where are files stored on an Android emulator?

大憨熊 提交于 2019-12-11 02:44:12

问题


I am working on a small program on Android to write some hard-coded text to a file with a hard-coded name. While the operation is successful (there are no errors), I am not able to find the file on the emulator. My questions:

  1. Where are the files written?
  2. What is the file path I need for files to be stored on the home screen or the applications page (in general, a place where the UI can get to)?

The code:

public class MainActivity extends Activity {

    Button writeFile;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    writeFile = (Button) findViewById(R.id.writeFile);
    writeFile.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                //Step 1. Get file name.
                String file = "hello_files.txt";
                String str = "hello world";

                Log.v(this.toString(), "Going to write to a file.");
                FileOutputStream fos;
                try {
                    fos = openFileOutput(file, MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);
                    fos.write(str.getBytes());
                    Log.v(this.toString(), "Local path = ");
                    fos.close();
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    Log.v(this.toString(), "File not found!!");
                    e.printStackTrace();
                } catch (IOException e) {
                    Log.v(this.toString(), "IO Exception.");
                    e.printStackTrace();
                }
            }
        });
}

回答1:


Files are stored in "/mnt/sdcard/" (External storage) or "/data/data/Your Package Name/" (Internal storage) (as in this question). You can access this folder from this package only (unless the phone is rooted).

The second part of your question is not very clear. From what I can understand, Android is not like Windows (no desktop folder). To create a shortcut on the desktop, you need to implement an App widget.



来源:https://stackoverflow.com/questions/12998098/where-are-files-stored-on-an-android-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!