openFileOutput("textfile.txt",
MODE_PRIVATE);
method untuk membuat file txt dengan nama textfile.txt sesuai yg
terdapat di parameternya, dengan mode private / default.
OutputStreamWriter(fOut);
Class yg di panggil untuk mampilkan file text dgn parameter variabel
berisi method openFileOutput().
openFileInput("textfile.txt);
method untuk membuka file txt dengan nama textfile.txt sesuai yg
terdapat di parameternya.
InputStreamReader(fIn);
Class yg di panggil untuk mamasukkan file text dgn parameter variabel
berisi method openFileInput().
MODE_PRIVATE
File
creation mode: the default mode, where the created file can only be accessed by
the calling application.
Mode pembuat
File: mode awal atau default dimana saat membuat filenya hanya dapat dilakukan
dgn memanggil aplikasi.
MODE_APPEND
File
creation mode: for use with openFileOutput(String, int), if the file already
exists then write data to the end of the existing file instead of erasing it
Digunakan
dgn method openFileOutput(String, int),
jika file yg hendak kita buat sudah ada maka menuliskan data sampai akhir dr
file yg ada bahkan menghapusnya.
MODE_WORLD_READABLE
This
constant was deprecated in API level 17. Creating world-readable files is very
dangerous, and likely to cause security holes in applications. It is strongly
discouraged; instead, applications should use more formal mechanism for
interactions such as ContentProvider, BroadcastReceiver, and Service. There are
no guarantees that this access mode will remain on a file, such as when it goes
through a backup and restore. File creation mode: allow all other applications
to have read access to the created file.
MODE_WORLD_WRITEABLE
This constant
was deprecated in API level 17. Creating world-writable files is very
dangerous, and likely to cause security holes in applications. It is strongly
discouraged; instead, applications should use more formal mechanism for
interactions such as ContentProvider, BroadcastReceiver, and Service. There are
no guarantees that this access mode will remain on a file, such as when it goes
through a backup and restore. File creation mode: allow all other applications
to have write access to the created file
Pemberkasan ini berkaitan jg dengan tutorial berikut http://coverhidupku.blogspot.com/2014/04/tutorial-menampilkan-biodata.html
untuk menulis file atau membuat file text, masukkan kode ini pada method fungsi yg memiliki aksi eksekusi aplikasi contohnya tombol maka kode berikut sisipkan pada method klikSubmit().
try
{
FileOutputStream fOut =
openFileOutput("simpanoi.txt", MODE_PRIVATE);
OutputStreamWriter osw = new
OutputStreamWriter(fOut);
osw.write("File:"+namahere.getText()+emailhere.getText()+ jkhere.getText()+ hobihere.getText());
osw.close();
Toast.makeText(getBaseContext(),
"File tersimpan dalam txt guys",Toast.LENGTH_SHORT).show();
} catch(IOException ioe){
ioe.printStackTrace();
sedangkan kode berikut untuk membaca file teks yg dipanggil, peletakaan kodingnya jg sama.
try
{
FileInputStream fIn =
openFileInput("simpanIN.txt");
InputStreamReader isr = new
InputStreamReader(fIn);
char[]
inputBuffer = new char[READ_BLOCK_SIZE];
String s = "";
int
charRead;
while((charRead
= isr.read(inputBuffer))>0)
{
String readString = String.copyValueOf(inputBuffer, 0,
charRead);
s += readString;
inputBuffer = new
char [READ_BLOCK_SIZE];
}
isr.close();
Toast.makeText(getBaseContext(),
"File txtnya sudah terLOAD guys" + s ,Toast.LENGTH_SHORT).show();
} catch(IOException
ioe){
ioe.printStackTrace();