how can I copy files to the file system of android?

前端 未结 5 835
深忆病人
深忆病人 2021-02-10 06:05

How can I copy files to the file system (place) in android? How can I access it?

相关标签:
5条回答
  • 2021-02-10 06:18

    copy files from android to local

    adb pull /data/data/com.example.sample ./sample/
    

    copy file to android from local

    adb push ./sample/ /sdcard/sample/
    
    0 讨论(0)
  • 2021-02-10 06:18

    You can use:

    Environment.getExternalStorageDirectory()
    

    That will give you /sdcard if your device has an sdcard, or something different in other cases. For example the Archos.

    0 讨论(0)
  • 2021-02-10 06:30

    I took some time to research about android's system files earlier, but almost always with android x86, i found out that the /system folder inside android is read-only,

    it is an image with format is SFS format, this is read-only image format of linux so i don't think you can copy some thing inside this folder. I not sure about rooted android. Hope it will help you.

    0 讨论(0)
  • 2021-02-10 06:36

    You can probably hide your file in the sdcard by prefixing it with a dot (ex: .myfile)

    0 讨论(0)
  • 2021-02-10 06:40

    I'm not sure if this is what you're asking, but here's another interpretation of your question:

    You can place files in the assets folder in the project on your development machine. They will be bundled into the apk file and then access them through the AssetManager class. Something like this from within a Service or Activity class:

    AssetManager am = getAssets();
    InputStream is = am.open("filename");
    

    This will allow you to read the contents of those files. I don't believe you can write to them though. There are other options for if you need to read and write files in your application's storage sandbox. This is done by calling openFileOutput(). I should note though that the user can always access the files on the device through ddms but other applications won't be able to access files stored in your application's storage sandbox.

    Edit Based on your comment, you probably want to use

    OutputStream out = openFileOutput("outfile");
    

    to write to a file from your code. This code must be called from within an Activity or Service (something that extends Context). This file will be stored on the phone's file system and not on the sdcard. These files will not be accessible to the average user. If users know how to enable usb debugging then they will be able to access them and there is really no way around this.

    0 讨论(0)
提交回复
热议问题