Android文件操作
2010-09-07 10:43:00 来源:WEB开发网个人总结的【Android文件操作】手机开发必须技术
/**
* 【文件操作】
*/
package Iwit.IwitTest;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import android.content.Context;
import android.widget.Toast;
/**
* @author Shine
*【文件读,写】
*/
public class FileOperate
{
/**
* 【读取文件】
* @param context
* @param fileName
* @return
*/
public String ReadText(Context context,String fileName)
{
FileInputStream fIn = null;
InputStreamReader isr = null;
char[] inputBuffer = new char[255];
String data = null;
try
{
fIn =context.openFileInput(fileName);
isr = new InputStreamReader(fIn);
isr.read(inputBuffer);
data = new String(inputBuffer);
Toast.makeText(context, "read Succeed",Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
e.printStackTrace();
Toast.makeText(context, " not read",Toast.LENGTH_SHORT).show();
}
finally
{
try {
isr.close();
fIn.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return data;
}
/**
* 【写入文件】
* @param context
* @param fileName
* @param data
*/
public void WriteText(Context context, String fileName,String data)
{
FileOutputStream fOut = null;
OutputStreamWriter osw = null;
更多精彩
赞助商链接