streamhomework.java
来自「用户输入信息」· Java 代码 · 共 48 行
JAVA
48 行
package lesson20;
import java.io.*;
public class StreamHomeWork {
public static void main(String[] args) {
System.out.println("***************");
PrintStream ps = null;
FileOutputStream fos = null;
BufferedReader br = null;
String str = "";
try {
fos = new FileOutputStream("F:/myFile.txt");
ps = new PrintStream(fos);
System.out.println("请您输入您所要输入的内容:……");
br = new BufferedReader(new InputStreamReader(System.in));
try {
while ((str = br.readLine()) != null) {
if (str.equals("quit") || str.equals("exit")) {
ps.close();
br.close();
fos.close();
return;
}
ps.println(str);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
ps.close();
try {
br.close();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?