0
点赞
收藏
分享

微信扫一扫

Java--如何读取文件中的数据

知年_7740 2022-02-01 阅读 64

祝福语:祝大家2022年新春快乐!!!

IT_WEH_coder

1 文件读取步骤

IT_WEH_coder

2 效果展示

3 实例代码

package demo01;

import java.io.*;

public class ReadData {
    public static void main(String[] args) throws IOException {
        File file_1 = new File("F:/Java/file");
        if (!file_1.exists()) {
            file_1.mkdirs();
        }
        File file_2 = new File(file_1.getPath(),"Text.docx");
        if (!file_2.exists()) {
            file_2.createNewFile();
        }
        Reader r = new InputStreamReader(new FileInputStream(file_2),"GBK");
        StringBuffer sbf = new StringBuffer();
        int b =-1;
        while ((b=(int)r.read() )!=-1){
            char c = (char)b;
            sbf.append(c);
        }
        r.close();
        System.out.println(sbf.toString());
        System.out.println("end!");
    }
}

举报

相关推荐

0 条评论