Java基於IO流讀取文件的辦法。本站提示廣大學習愛好者:(Java基於IO流讀取文件的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是Java基於IO流讀取文件的辦法正文
本文實例講述了Java基於IO流讀取文件的辦法。分享給年夜家供年夜家參考,詳細以下:
public static void readFile(){ String pathString = TEST.class.getResource("/simu").getFile(); try { pathString = URLDecoder.decode(pathString, "utf-8"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } System.out.println(pathString); File file = new File(pathString,"test.txt"); InputStream is = null; try { is = new FileInputStream(file); } catch (Exception e) { e.printStackTrace(); } BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuffer sb = new StringBuffer(""); String b = ""; try { while((b=br.readLine())!=null){ sb.append(b).append("\n"); } } catch (Exception e) { e.printStackTrace(); } String bb = sb.toString(); System.out.println(bb); }
願望本文所述對年夜家Java法式設計有所贊助。