java例程练习(缓冲流)
2012-05-02 16:59
381 查看
import java.io.*; public class Test { public static void main(String[] args) { try { FileInputStream fis = new FileInputStream("C:/java/Test.java"); BufferedInputStream bis = new BufferedInputStream(fis); int c = 0; System.out.println(bis.read()); System.out.println(bis.read()); bis.mark(100); for(int i = 0; i <= 10 && (c = bis.read()) != -1; i++) { System.out.print(c+ " "); } System.out.println(); bis.reset(); for(int i = 0; i <= 10 &&(c = bis.read()) != -1; i++) { System.out.print(c + " "); } bis.close(); } catch (FileNotFoundException e) { System.out.println("文件不存在"); } catch (IOException e) { System.out.println("读取异常"); } } }
import java.io.*; public class TTest { public static void main(String[] args) { try { BufferedWriter bw = new BufferedWriter(new FileWriter("C:/java/Test_Bak.txt")); BufferedReader br = new BufferedReader(new FileReader("C:/java/Test.java")); String s = null; for(int i = 0; i <= 100; i++) { s = String.valueOf(Math.random()); bw.write(s); bw.newLine(); } bw.flush(); while((s = br.readLine()) != null) { System.out.println(s); } bw.close(); br.close(); } catch (FileNotFoundException e) { System.out.println("文件不存在"); } catch (IOException e) { System.out.println("读取异常"); } } }
相关文章推荐
- java例程练习(缓冲流)
- java例程练习(缓冲流)
- java例程练习(一维数组)
- java例程练习(计算子串个数)
- java例程练习(将string转成double)
- java例程练习(用递归方法列出文件目录)
- java例程练习(List常用算法)
- java例程练习(字符流)
- java例程练习(数据流)
- java例程练习(打印流)
- java例程练习(多线程[sleep()方法])
- java例程练习(多线程[线程同步问题])
- java例程练习(网络编程[简单UDP通信试验])
- java例程练习(Circle类和Point类柔和练习)
- java例程练习(对象转型及instanceof关键字)
- java例程练习(自定义异常处理)
- java例程练习(计算子串个数)
- java例程练习(将string转成double)
- java例程练习(枚举Enum类)
- java例程练习(东软笔试题[n阶平面魔方])