JAVA讀取本地文件

import java.io.*;

/**
 * Created by PC on 2016/8/4.
 */
public class JsonTest {
    public static void main(String[] args) throws IOException {
            try {
                InputStream in = new FileInputStream("C:\\Users\\PC\\Desktop\\comment.txt");
                BufferedReader b = new BufferedReader(new InputStreamReader(in));
                String d = null;
                StringBuilder sd = new StringBuilder();
                while ((d = b.readLine()) != null) {
                    sd.append(d);
                    sd.append("\n");
                }
                System.out.println(sd.toString());
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
}
相關文章
相關標籤/搜索