码迷,mamicode.com
首页 > 其他好文 > 详细

Bufferread有readline()使得字符输入更加方便

时间:2018-08-05 13:10:24      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:system   access   rand   style   tst   har   sys   tput   des   

原则:保证编解码方式的统一,才能不至于出现错误。

Io包的InputStreamread称为从字节流到字符流的桥转换类。这个类可以设定字符转换方式。

OutputStreamred:字符到字节

Bufferread有readline()使得字符输入更加方便。

在I/O流中,所有输入方法都是阻塞方法。

Bufferwrite给输出字符加缓冲,因为它的方法很少,所以使用父类printwrite,它可以使用字节流对象,而且方法很多。

 

 

 1 package TomTexts;
 2 import java.io.*;
 3 public class TomTexts_33 {
 4 
 5     public static void main(String[] args)
 6     {    String str1;
 7         char ch1;
 8         int n;
 9         try{
10             File mytxt=new File("read.txt");
11             RandomAccessFile ra=new RandomAccessFile(mytxt,"rw");
12             ra.write("This is the first sentence".getBytes());
13             ra.writeChar(‘\n‘);
14             ra.write("Java Program Design".getBytes());
15             ra.writeChar(‘\n‘);
16             ra.seek(0);
17             str1=ra.readLine();
18             System.out.println(str1);
19             ra.seek(18);
20             System.out.println(ra.readLine());
21             ra.close();
22         }
23 catch(IOException e)
24         {
25             System.out.println(e.toString());
26         }
27     }
28 
29 
30 }

 

Bufferread有readline()使得字符输入更加方便

标签:system   access   rand   style   tst   har   sys   tput   des   

原文地址:https://www.cnblogs.com/borter/p/9425038.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!