【问题标题】:Where are files stored on an Android emulator?Android模拟器上的文件存储在哪里?
【发布时间】:2012-10-11 11:25:08
【问题描述】:

我正在开发一个 Android 上的小程序,将一些硬编码文本写入具有硬编码名称的文件。虽然操作成功(没有错误),但我无法在模拟器上找到该文件。我的问题:

  1. 文件写在哪里?
  2. 要存储在主屏幕或应用程序页面(通常是 UI 可以到达的位置)上的文件需要什么文件路径?

代码:

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

【问题讨论】:

    标签: android file file-io android-emulator


    【解决方案1】:

    文件存储在“/mnt/sdcard/”(外部存储)或“/data/data/Your Package Name/”(内部存储)中(如question)。您只能从此包中访问此文件夹(除非手机已root)。

    你问题的第二部分不是很清楚。据我了解,Android 不像 Windows(没有桌面文件夹)。要在桌面上创建快捷方式,您需要实现一个 App 小部件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-08
      • 2013-09-14
      • 2012-10-17
      • 1970-01-01
      • 2015-03-08
      • 2023-04-02
      • 2010-12-03
      • 2017-11-04
      相关资源
      最近更新 更多