且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-10-15 09:58:45

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

如果你想在你的应用程序目录中写入文件,那么你的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!
}