SomeOne989
SomeOne989

Reputation: 1

Working with files (Storing array of strings) Android

I'm new in android programming and I have a problem.

I can't find how to create and store data in file.

I need to create a file (non text file) that will store array of strings (example: Array{Nick, James, Director, 005001235NICK JAMES}.

I know how this work in delphi and I could do it in few minutes, but with android I'm not familiar jet. Can anyone help me?

Thank you and best regards.

Upvotes: 0

Views: 55

Answers (1)

Sahar Avr
Sahar Avr

Reputation: 1168

You might find org.apache.commons.io.FileUtils and java.io.File useful. Before any writing is possible, your manifest must include an appropriate permission decleration. To write to the external storage, use:

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

Here is a sample code that uses java.io.File to write a bitmap to file:

private void writeBitmapToFile(Bitmap bmp, File file) {
    try (final FileOutputStream out = new FileOutputStream(file)) {
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Upvotes: 4

Related Questions