package New_IO;
import java.io.*;
/**
-
标准的输入流
*/
public class Test4 {
public static void main(String[] args) {
try {
// Test4.testSystemIn();
// Test4.writeTXT(“F:\Java_project_new\src\New_IO\tt5.txt”);
Test4.test(“F:\Java_project_new\src\New_IO\tt5.txt”);
} catch (Exception e) {
e.printStackTrace();
}}
public static void testSystemIn() throws Exception{
//创建一个接收键盘输入数据的输入流
InputStreamReader is = new InputStreamReader(System.in);
//把输入流放到缓冲流里
BufferedReader br = new BufferedReader(is);
String str = “”; //定义一个临时接收数据的字符串
while ((str = br.readLine()) !=null){
System.out.println(str);
}
br.close();
is.close();
}
/**-
把控制台输入的内容写到指定的TxT文件中,当接收到字符串over,就结束程序的运行
*/
public static void writeTXT(String input) throws Exception{
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(is);
BufferedWriter bw = new BufferedWriter(new FileWriter(input));
String str = “”; //定义一个临时接收数据的字符串
while ((str = br.readLine()) !=null){
if (str.equals(“over”)){ // 判断接收存储的值是否为over
break;
}
bw.write(str); //将str里的数据写入到硬盘}
bw.flush();
bw.close();
br.close();
is.close();
}
//根据指定文件里的字段判断是否成功
public static void test(String input) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedReader b = new BufferedReader(new FileReader(input));
String str = “”;
while ((str = br.readLine()) !=null){
if (str.equals(b.readLine())){
System.out.println(“登录成功”);
break;
}else {
System.out.println(“error”);
}}
br.close();
}
-
}