78.txt

来自「是一个 java 基础学习软件 有设计说明」· 文本 代码 · 共 54 行

TXT
54
字号
import java.io.*;


//
// 创建一个BufferedReader对象从键盘逐行读入数据

public class ReadlineTest {
   public static void main (String args[]) 
   {
		String s;
				
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try 
		{		// 每读入一行后向显示器输出
			s = br.readLine();
			while (!s.equals("")) 
			{  	
		        System.out.println("Read: " + s);
		        s = br.readLine();
			}
			br.close(); // 关闭输入流
	
		}
		 catch (IOException e) { // 捕获可能的IOException.
			e.printStackTrace();
		}
    }
}
//

// 从文件读入
import java.io.*;
public class ReadTxtTest{
	  public static void main(String[] args){
		try{
			FileInputStream in=new FileInputStream("myfile.txt");
			int b;	b = in.read();
			while(b!= -1)       {
				System.out.print((char)b);
				b = in.read();
			}
			in.close();
		}catch (IOException e) {
		        System.out.println(e);
		        System.out.println(e.getLocalizedMessage());
		        e.printStackTrace();
		        System.out.println(e.getMessage());
		}finally {
		        System.out.println(" It’s ok!");
		}
	  }
}
//

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?