62,620
社区成员
发帖
与我相关
我的任务
分享import java.io.*;
public class Test3{
public static void main(String[] args) throws IOException{
writeSomeToFile("result.rst","1 + 2 = 3");
String s=readLineFromFile("result.rst");
String[] strs=s.split("\\s+"); //split whith white charactor
for(int i=0;i<strs.length;i++){
System.out.println(strs[i]);
}
}
public static void writeSomeToFile(String fileName,String some) throws IOException{
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(fileName)),"UTF-8"));
bw.write(some,0,some.length());
bw.newLine();
bw.flush();
bw.close();
}
public static String readLineFromFile(String fileName) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(new File(fileName))));
String s=null;
s=br.readLine();
br.close();
return s;
}
}