zoukankan      html  css  js  c++  java
  • FileWriter和FileReader简单使用

    FileWriter和FileReader使用

    package com.main.test;
    
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    
    public class FileWriterTest {
    	static FileWriter fw;
    	static FileReader fr;
    	public static void main(String[] args) throws IOException {
    		// TODO Auto-generated method stub
                 //  fileWriter();
    		//FileReaderDemo();
    		//whileFileReader();	
    		//whileFileReader2();
            //   shuZuReadDemo();
    	}
    	private static void shuZuReadDemo() throws FileNotFoundException,
    			IOException {
    		fr = new FileReader("c:\田藩.txt");
               char[] ch = new char[3];
               fr.read(ch);
               for(int i= 0 ;i<ch.length;i++){
            	   System.out.println(ch[i]+"");
               }
    	}
    	private static void whileFileReader2() throws FileNotFoundException,
    			IOException {
    		fr = new FileReader("c:\田藩.txt");
    	    int ch =0;
    	    while((ch=fr.read())!=-1){
    	    	System.out.println((char)ch);
    	    }
    	}
    	private static void whileFileReader() throws FileNotFoundException,
    			IOException {
    		fr = new FileReader("c:\田藩.txt");
    		while(true){
    			int ch = fr.read();
    			if(ch == -1){
    				break;
    			}
    			System.out.println((char)ch);
    		}
    		fr.close();
    	}
    	private static void FileReaderDemo() throws FileNotFoundException,
    			IOException {
    		fr = new FileReader("c:\田藩.txt");
    	    int ch =fr.read();
    	    int ch2 =fr.read();
    	    System.out.println((char)ch);
    	    System.out.println((char)ch2);
    	}
    	private static void fileWriter() throws IOException {
    		try {
    			 fw = new FileWriter("c:\田藩.txt",true);
    			fw.write("#eoeoeo");
    			
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}finally{
    			fw.close();	
    		}
    	}
    
    }
    

      

  • 相关阅读:
    H3C 配置vlan及vlan间路由
    H3C 端口安全技术
    H3C 备份系统应用程序与文件
    H3C 类似于Linux编辑命令
    H3C telnet
    H3C基本命令
    Python里的目录
    Python 模块
    Python 函数
    JS 100内与7相关的数
  • 原文地址:https://www.cnblogs.com/childhooding/p/4777990.html
Copyright © 2011-2022 走看看