JAVA实例

 JAVA实例1 
1
package Demo3; 2 3 import java.io.File; 4 import java.io.FileReader; 5 import java.io.IOException; 6 7 8 public class Demo2 { 9 10 11 public static void main(String[] args) 12 { 13 FileReader fileReader = null; 14 try{ 15 //找到目标文件 16 File file = new File("e:\Java\a.txt"); 17 //建立程序与文件的数据通道 18 fileReader = new FileReader(file); 19 //读取文件 20 char[] buf = new char[2056]; 21 int length = 0; 22 length = fileReader.read(buf); 23 System.out.println("读取到的内容:"+ new String(buf,0,length)); 24 }catch(IOException e){ 25 System.out.println("读取资源文件失败...."); 26 }finally{ 27 try{ 28 //关闭资源 29 fileReader.close(); 30 System.out.println("释放资源文件成功...."); 31 }catch(IOException e){ 32 System.out.println("释放资源文件失败...."); 33 } 34 } 35 36 } 37 38 }
在代码的世界尽情的翱翔吧!
原文地址:https://www.cnblogs.com/maleyang/p/10295659.html