//写入
public class WriterFile {
public boolean WriterFile(String text,String path) throws Exception{
boolean b=false;
try{
FileOutputStream fos=new FileOutputStream(path,true);
OutputStreamWriter osw=new OutputStreamWriter(fos,"utf-8");
osw.write(text);
osw.close();
b=true;
}catch (Exception e) {
e.printStackTrace();
}
return b;
}
}
//读取
public class ReadFiles {
public String ReadFiles(String file) throws Exception{
String context="";
try {
FileInputStream fis=new FileInputStream(file);
InputStreamReader isr;
isr = new InputStreamReader(fis,"utf-8");
int d=-1;
while((d=isr.read())!=-1){
context+=(char)d;
}
isr.close();
}catch (Exception e) {
e.printStackTrace();
}
return context;
}
}
java 读取和写入 txt文件
最新推荐文章于 2023-03-29 10:46:43 发布