13.BufferedReader
发表日期:2022-08-05 16:17:46 | 来源: | | 浏览(634) 分类:JAVA基础
ReaderDemo01
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class ReaderDemo01 { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub File file = new File("d:" + File.separator + "OutputStreamDemo.txt"); FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); String str = null; while ((str = br.readLine()) != null) { System.out.println(str); } fr.close(); br.close(); /* FileReader fReader = null; try { fReader = new FileReader(file); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } BufferedReader bReader = new BufferedReader(fReader); try { System.out.print(bReader.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } */ } }
ReaderDemo02
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; public class ReaderDemo02 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub InputStream is = System.in;//字节流 InputStreamReader isr = new InputStreamReader(is);//转换为字符流 BufferedReader br = new BufferedReader(isr); System.out.println("请输入内容"); String str = null; while ((str = br.readLine())!=null) { if ("exit".equals(str)) { break; } System.out.println(str); } is.close(); isr.close(); br.close(); System.out.println("bye!"); /* BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in)); String string = null; System.out.println("请输入内容"); try { string = bReader.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("输入内容:"+string); */ } }
ExecDemo01
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class ExecDemo01 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub int i = 0 ; int j = 0 ; BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in)); String string = null; System.out.println("请输入第一个数字:"); string = bReader.readLine(); i = Integer.parseInt(string); System.out.println("请输入第二个数字:"); string = bReader.readLine(); j = Integer.parseInt(string); System.out.println(i+"+"+j+"="+(i+j)); } }
- JAVA(0)
- JAVA基础(30)
- 1.JAVA开发环境配置(0)
- 2.java数据类型(0)
- 3.数组(0)
- 4.Date(0)
- 5.String 和 StringBuffer类常用方法(0)
- 6.Math类(0)
- 7.Cloneable(0)
- 8.File 文件(0)
- 9.FileReader和FileWriter(0)
- 10.RandomAccessFile(0)
- 11.FileInputStream和FileOutputStream(0)
- 12.InputStreamReader和OutputStreamWriter(0)
- 13.BufferedReader(0)
- 14.Scanner(0)
- 15.DataOutputStream(0)
- 16.Thead 多线程(0)
- 17.TimerTask(0)
- 18.zip(0)
- 19.Charset(0)
- 20.List(0)
- 21.Map(0)
- 22.Properties(0)
- 23.Enumeration(0)
- 24.Collection(0)
- 25.JDBC(0)
- 26.Iterator(0)
- 27.Abstract(0)
- 28.Interface(0)
- 29.Serializable(0)
- 30.Camparable(0)
- JSP基础(50)