存储到磁盘的代码:
BufferedWriter bw
= null;
try {
bw
= new BufferedWriter(new FileWriter("hello.tetx"));
bw
.write("hello");
} catch (IOException e
) {
e
.printStackTrace();
} finally {
if (bw
!=null){
try {
bw
.close();
} catch (IOException e
) {
e
.printStackTrace();
}
}
}
读入到编译器的代码:
BufferedReader br
= null;
try {
br
= new BufferedReader(new FileReader("hello.tetx"));
String s
;
while ((s
=br
.readLine())!=null){
System
.out
.println(s
);
}
} catch (IOException e
) {
e
.printStackTrace();
} finally {
if (br
!=null){
try {
br
.close();
} catch (IOException e
) {
e
.printStackTrace();
}
}
}
转载请注明原文地址:https://tech.qufami.com/read-26657.html