文件逐行读取-转码

没啥技术含量,就是个容易忘记的代码


package cn.swsk.xbry.md1000.controller;

import org.apache.commons.io.FileUtils;

import java.io.*;
import java.util.Scanner;

/**
 * @author css
 * @date 2019/8/20 15:33
 */
public class Test {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\SWSK\\XBRY\\lightningPosition\\flash2019060523.txt");
//        System.out.println(FileUtils.readFileToString(file));
//        System.out.println(FileUtils.readFileToString(file,"UTF-8"));
//        System.out.println(FileUtils.readFileToString(file,"GBK"));
        InputStream is = FileUtils.openInputStream(file);
        InputStreamReader isr = new InputStreamReader(is,"GBK");
        BufferedReader reader = new BufferedReader(isr);
        String s = reader.readLine();
        System.out.println(s);
    }
}

posted on 2019-08-20 16:19  疯狂的妞妞  阅读(357)  评论(0编辑  收藏  举报

导航