• IO流读取文件内容时,出现空格的问题(未找到原因)


    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.Arrays;
    
    public class TestFileWriter {
    	public static void main(String[] args) throws IOException {
    		File i = new File("D:\Huang\123.txt");
    		FileReader r = new FileReader(i);
    		FileWriter w = new FileWriter("D:\Huang\abcd.txt");
    		StringBuilder sb = new StringBuilder();
    		int b = -1;
    		char[] cs = new char[(int) i.length()];
    		int num = 0;
    		System.out.println(i.length());
    		while ((b = r.read(cs)) != -1) {
    			sb.append(cs);
    			System.out.println((num++) + Arrays.toString(cs));
    			System.out.println((num++) + String.valueOf(cs));//打印输出时   会输出空格
    		}
    		w.write(sb.toString());
    		w.flush();
    		r.close();
    		w.close();
    
    	}
    

      

  • 相关阅读:
    3.10 Go Map哈希表
    3.9 Go Slice切片
    3.8 Go Array数组
    3.7 Go指针
    3.6 Go String型
    3.5 Go布尔型
    3.4 Go字符型
    3.3 Go浮点型
    3.2 Go整数类型
    3.1Go变量
  • 原文地址:https://www.cnblogs.com/1020182600HENG/p/6738177.html
Copyright © 2020-2023  润新知