找不到我的Andr​​oid平板电脑创建的文件我的、找不到、平板、文件

2023-09-04 06:17:28 作者:云朵上的棉花糖

在Android的

/ data目录是空的。我已经安装了一些应用程序,我还写了code以创建/数据的文件/目录下的MyApp,

我在onCreate方法这些行,但我没有看到运行程序后,在/ data目录中的所有文件。

 文件FILEDIR = getFilesDir();
    串FILEDIR = fileDir.toString();
    Log.v(TEST,FILEDIR  - >中+ FILEDIR);

       //输出我得到的是FILEDIR ---> /data/data/com.android.Test/files

    字符串strNewFileName =test1.txt的;
    字符串strFileContents =我第一个文件创建PRGM;

    文件NEWFILE =新的文件(FILEDIR,strNewFileName);
    尝试{

            布尔FILESTAT = newFile.createNewFile();
            Log.v(TEST,创建文件=>中+ FILESTAT);

                //输出为创建文件=>真表示成功

            FileOutputStream中FO =
            新的FileOutputStream(newFile.getAbsolutePath());
            fo.write(strFileContents.getBytes());
            fo.close();
    }
    赶上(IOException异常E)
    {Log.v(TEST,异常上创建);}
 

解决方案

在实际的设​​备,你看不到这些文件夹,如果它不是扎根。看到这个的问题。

如果你想在你的应用程序目录中写入文件,那么你的code是确定。您可以检查它的存在在创建它以同样的方式 - 从您的应用程序:

  myfile文件=新的文件(getFilesDir()+/test1.txt);
如果(myFile.exists())
{
  //好!
}
 

/data directory in android is empty. I have installed a few applications and i also wrote code to create a file in /data/Myapp directory ,

I have these lines in OnCreate method , but i dont see any files in /data directory after running the program.

    File fileDir = getFilesDir();
    String filedir=fileDir.toString();
    Log.v("TEST","FILEDIR--->"+filedir);

       //output i got is FILEDIR--->/data/data/com.android.Test/files

    String strNewFileName = "test1.txt";
    String strFileContents = " MY FIRST FILE CREATION PRGM";

    File newFile = new File(fileDir, strNewFileName);
    try{

            boolean filestat = newFile.createNewFile();
            Log.v("TEST"," CREATE FILE =>"+ filestat);

                //output is CREATE FILE =>true indicating success

            FileOutputStream fo =
            new FileOutputStream(newFile.getAbsolutePath());
            fo.write(strFileContents.getBytes());
            fo.close();
    }
    catch(IOException e) 
    {Log.v("TEST","Exception on create ");}

解决方案

On real device, you can't see these folders if it's not rooted. see this question.

If you want to write files in your app directory, then your code is OK. You can check that it is there in the same way you created it - from your application:

File myFile = new File(getFilesDir() + "/test1.txt");
if (myFile.exists())
{
  //Good!
}