zoukankan      html  css  js  c++  java
  • FileRead方法

    package test;
    
    
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.math.BigDecimal;
    import java.nio.channels.NonReadableChannelException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.*;
    
    public class Main {
    
    	private static final String space_operator = " ";
    	private static final double pi = Math.PI;
    	private static final String LINE_SEPARATOR = System.getProperty("line.separator");
    	public static void main(String[] args) throws Exception {
    
    		FileReader fr = new FileReader("demo.txt");
    		
    		/*
    		 * 第一种方法一个字符一个字符的读取
    		 */
    		/*
    		int ch = 0;
    		while((ch = fr.read()) != -1)
    		{
    			System.out.print((char)ch);
    		}
    		*/
    		
    		/*
    		 * 第二种方法我们直接将内容读到一个字符数组里面
    		 * 返回的参数是读到了几个字符
    		 */
    		int len = 0;
    		char[] buf = new char[1024];
    		while((len = fr.read(buf)) != -1)
    		{
    			/*
    			 * 直接转换成为字符串
    			 * 用字符串的构造函数
    			 */
    			System.out.println(new String(buf,0,len));
    		}
    		
    	
    	}
    }
    

      

  • 相关阅读:
    [NOI2019] 回家路线
    [NOIP2016] 天天爱跑步
    [CF1187D] Subarray Sorting
    [THUPC2018] 弗雷兹的玩具商店
    [AGC006C] Rabbit Exercise
    [AGC005F] Many Easy Problems
    [51Nod2558] 选址
    [BZOJ3771] Triple
    [APIO2019] 奇怪装置
    [CTSC2018] 假面
  • 原文地址:https://www.cnblogs.com/WINDZLY/p/11788754.html
Copyright © 2011-2022 走看看