zoukankan      html  css  js  c++  java
  • java例程练习(字符流)

    import java.io.*;
    
    public class TestFileReader {
    	public static void main(String[] args) {
    		FileReader fr = null;
    		int c = 0;
    		try {
    			fr = new FileReader("C:/java/Test.java");
    			
    			while((c = fr.read()) != -1) {
    				System.out.print((char)c);
    			}
    			fr.close();
    		} catch (FileNotFoundException e) {
    			System.out.println("找不到指定文件");
    		} catch (IOException e) {
    			System.out.println("文件读取错误");
    		}
    	}
    }
    
    import java.io.*;
    
    
    public class TestFileWriter {
    	public static void main(String[] args) {
    		FileWriter fw = null;
    		
    		try {
    			fw = new FileWriter("C:/java/unicode.txt");
    			for(int c = 0; c <= 50000; c++) {
    				fw.write(c);
    			}
    			fw.close();
    		} catch (IOException e) {
    			System.out.println(e.getMessage());
    			System.out.println("文件写入错误");
    			System.exit(-1);
    		}
    	}
    }
    


  • 相关阅读:
    数据库(六)
    数据库(五)
    数据库(四)
    数据库(三)
    数据库(二)
    数据库
    函数 枚举和递归
    数据类型(四) 集合
    数据库基础
    特殊集合 结构体
  • 原文地址:https://www.cnblogs.com/wjchang/p/3671703.html
Copyright © 2011-2022 走看看