读取文件内容,并输出到控制台,新版、旧版
新版
String f="d:/Auser/d.txt"; FileInputStream fis = null; //读取文件内容,并输出到控制台,新版 try { fis = new FileInputStream("d:/Auser/d.txt"); System.out.println(new String(fis.readAllBytes())); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
旧版
String f="d:/Auser/d.txt"; FileInputStream fis = null; try { fis = new FileInputStream(f); byte[] buf =new byte[1024]; int len =0; while ((len=fis.read(buf))>0){ System.out.println(new String(buf,"utf-8")); } fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
浙公网安备 33010602011771号