1) Place your txt file in assets.
2) At the first launch copy your txt file from assets to internal storage
Get InputStream of file in assets:
InputStream inputStream = am.open(inputFile);
Get OutputStream of file in internal storage:
File f = context.getFileStreamPath("filename.txt");
OutputStream outputStream = new FileOutputStream(f);
Copy data from input stream to output stream:
ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 8);
ReadableByteChannel ich = Channels.newChannel(inputStream);
WritableByteChannel och = Channels.newChannel(outputStream);
while (ich.read(buffer) > -1 || buffer.position() > 0)
{
buffer.flip();
och.write(buffer);
buffer.compact();
}
ich.close();
och.close();
3) Read data from internal storage:
File f = context.getFileStreamPath("filename.txt");
FileReader fr = new FileReader(f);
int chr = fr.read(); // read char
fr.close();
4) Write data to internal storage:
File f = context.getFileStreamPath("filename.txt");
FileWriter fw = new FileWriter(f);
fw.write("word"); // write string
fw.close();
You can use BufferedReader instead of FileReader for read file line by line.