AndroidOptimist
AndroidOptimist

Reputation: 1449

Store the video info in a File

Currently am working in a project where I need to store online video url and total timing of the played video in a local storage (internal and external). But I don't know how to achieve that. Totally I have 5 videos and I need to maintain a file to store all the values.

Can anyone tell me how to achieve this? I referred Android's Saving Files training but cannot get a clear idea .

Upvotes: 0

Views: 111

Answers (2)

AndroidOptimist
AndroidOptimist

Reputation: 1449

Finally i Resolved my problem, i wrote files to external storage and store them as a text file with this :

FileOutputStream fos;
   try {
    fos = openFileOutput(fileName, Context.MODE_PRIVATE);
    fos.write(content.getBytes());
    fos.close();
    } 

This is really a simple thing which helped me to write and view my file as a text file. Hope this may help someone :-)

Upvotes: 1

android_dev
android_dev

Reputation: 1477

I guess you can use the device database(SQLite Database) to store the information

How to use, add and retrieve the data Just have a look into this sample

http://www.vogella.com/articles/AndroidSQLite/article.html

If you don't want to store the information just write that information into file and save that file in device.

/**
 * For writing the data into the file.
 * @param context
 * @param filename
 * @param data
 */

public static void writeData(Context context, String filename, String data) {
    FileOutputStream outputStream;

    try {
        outputStream = context.openFileOutput(filename,
                Context.MODE_PRIVATE);
        outputStream.write(data.getBytes());
        outputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

/**
 * For reading file from the device.
 * 
 * @param filename
 * @param context
 * @return
 */
private String getData(String filename, Context context) {
    StringBuffer data = new StringBuffer();
    try {
        FileInputStream openFileInput = context.openFileInput(filename);
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                openFileInput));
        String _text_data;
        try {
            while ((_text_data = reader.readLine()) != null) {
                data.append(_text_data);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return data.toString();
}

Upvotes: 0

Related Questions