存储在哪里上的Andr​​oid模拟器文件? [英] Where are files stored on an Android emulator?

查看:153
本文介绍了存储在哪里上的Andr​​oid模拟器文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android上工作的一个小程序,写一些硬codeD文本到一个文件中有硬codeD名称。虽然手术成功(没有错误),我无法找到在模拟器上的文件。我的问题:


  1. 在哪里文件写的?

  2. 什么是文件路径,我需要被存储在主屏幕或应用程序页面文件(一般来说,一个地方,用户界面​​可以得到)?

在code:

 公共类MainActivity延伸活动{    按钮WriteFile的;@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);    WRITEFILE =(按钮)findViewById(R.id.writeFile);
    writeFile.setOnClickListener(新OnClickListener(){            @覆盖
            公共无效的onClick(视图v){
                // TODO自动生成方法存根                //第1步:获取文件名。
                字符串文件=hello_files.txt;
                字符串str =Hello World的;                Log.v(this.toString(),会写一个文件。);
                FileOutputStream中FOS;
                尝试{
                    FOS = openFileOutput(文件,MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);
                    fos.write(str.getBytes());
                    Log.v(this.toString(),本地路径=);
                    fos.close();
                }赶上(FileNotFoundException异常五){
                    // TODO自动生成catch块
                    Log.v(this.toString(),找不到文件!);
                    e.printStackTrace();
                }赶上(IOException异常五){
                    Log.v(this.toString(),IO异常。);
                    e.printStackTrace();
                }
            }
        });
}


解决方案

文件存储在到/ mnt / SD卡/(外部存储)或/数据/数据​​/你的包名/(内部存储)(如在这个问题)。你可以从这个包只(除非手机是植根)访问此文件夹。

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

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

解决方案

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.

这篇关于存储在哪里上的Andr​​oid模拟器文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆