android 文件读写工具类

来源:互联网 发布:协和医院app挂号知乎 编辑:程序博客网 时间:2024/06/05 16:11

public class FileTools {

//读取txt文件中的内容

public static String readFile(File file) throws IOException{
FileInputStream inputStream = new FileInputStream(file);
int len=inputStream.available();
byte []buffer=new byte[len];
inputStream.read(buffer);
inputStream.close();
String content=new String(buffer);
return content;

}

//向txt文件中写入数据

public static void writeFile(File file,String content) throws IOException{
FileOutputStream outputStream = new FileOutputStream(file);
outputStream.write(content.getBytes());
outputStream.close();
}
}
0 0
原创粉丝点击