package com.infraware.file;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class fileactivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//파일 쓰기
FileOutputStream fos;
String strFileContents = "Test";
try {
fos = openFileOutput("Filename.txt",MODE_PRIVATE);
fos.write(strFileContents.getBytes());
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//파일 읽기
String strFileName = "Filename.txt";
StringBuffer strBuffer = new StringBuffer();
try {
FileInputStream fis = openFileInput(strFileName.toString());
DataInputStream dataIO = new DataInputStream(fis);
String strLine = null;
while( (strLine = dataIO.readLine()) != null)
strBuffer.append(strLine + "\n");
dataIO.close();
fis.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
TextView textView = new TextView(this);
textView.setText(strBuffer);
setContentView(textView);
}
}