lichen0921 发表于 2013-2-5 01:14:25

Java IO读写文件

<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>读文件
/** * 从文件读数据 */public void testRead() throws IOException {String filename = "D://aaa.txt";File file = new File(filename);FileReader fr = new FileReader(file);BufferedReader br = new BufferedReader(fr);String s = null ;while ( (s=br.readLine()) != null) {System.out.println(s);}br.close();fr.close();}
写文件
/** * 往文件写数据 */public void testWrite() throws IOException {String filename = "D://aaa.txt";File file = new File(filename);try {FileWriter fw = new FileWriter(file);BufferedWriter bw=new BufferedWriter(fw);PrintWriter out = new PrintWriter(fw);out.append("ssss");out.append("\r\n");out.append("ddddd");//out.flush(); out.close();fw.close();} catch (IOException e) {System.out.println("Uh oh, got an IOException error!");e.printStackTrace();}}
页: [1]
查看完整版本: Java IO读写文件