java通過file讀取txt文件內容

        String path="G:/test.txt";
        File file = new File(path); // 要讀取以上路徑的input。txt文件
        System.out.println(file.getName());
        byte[] bytes = new byte[1024];
        StringBuffer sb = new StringBuffer();
        FileInputStream in = new FileInputStream(file);
        int len;
        while ((len = in.read(bytes)) != -1) {
                sb.append(new String(bytes, 0, len));
            }
        System.out.println(sb.toString());

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章