Karudosu
Karudosu

Reputation: 1

Read a file out of an android application

I need to place a file on a specific folder, so that my application can read it. First i want to try to create a new file with a specific path, but anyway i try, on the android dev tool on eclipse, I have an IOException. Do you know a way to create "helloworld.txt" - For example - on the virtual device?

Thanks.

PS: I tried "new File(Environment.get..., "helloworld.txt").mkdirs();", and stuffs like that

Upvotes: 0

Views: 354

Answers (2)

ompemi
ompemi

Reputation: 91

If you want to create a file in the sdcard, you should check if the sdcard is ready (more info here), apart from the fact you need this permission in the AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Try not use hard-code the path of the sdcard, use instead the API for that.

On the other hand, if you want to create a private file on the phone storage you can use this methods:

FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);

Upvotes: 4

Sandy
Sandy

Reputation: 6353

You can not access system folder by using android app.You need to transfer the file from your system to Android Emulator's Virtual SD Card by using file explorer availble with ADT plugin for android in eclipse. Open file explorer in eclipse and import the file to device.

Upvotes: 0

Related Questions