åtxtæ件åå
¥å
容åºæ¬æ路就æ¯è·å¾ä¸ä¸ªfile对象ï¼æ°å»ºä¸ä¸ªtxtæ件ï¼æå¼I/Oæä½æµï¼ä½¿ç¨åå
¥æ¹æ³è¿è¡è¯»åå
容ï¼ç¤ºä¾å¦ä¸ï¼
package common;
ããimport java.io.*;
ããimport java.util.ArrayList;
ããpublic class IOTest {
ããpublic static void main (String args[]) {
ããReadDate();
ããWriteDate();
ãã}
ãã/**
ãã* 读åæ°æ®
ãã*/
ããpublic static void ReadDate() {
ããString url = âe:/2.txtâ;
ããtry {
ããFileReader read = new FileReader(new File(url));
ããStringBuffer sb = new StringBuffer();
ããchar ch[] = new char[1024];
ããint d = read.read(ch);
ããwhile(d!=-1){
ããString str = new String(ch,0,d);
ããsb.append(str);
ããd = read.read(ch);
ãã}
ããSystem.out.print(sb.toString());
ãã} catch (FileNotFoundException e) {
ããe.printStackTrace();
ãã} catch (IOException e) {
ããe.printStackTrace();
ãã}
ãã}
ãã/**
ãã* åå
¥æ°æ®
ãã*/
ããpublic static void WriteDate() {
ããtry{
ããFile file = new File(âD:/abc.txtâ);
ããif (file.exists()) {
ããfile.delete();
ãã}
ããfile.createNewFile();
ããBufferedWriter output = new BufferedWriter(new FileWriter(file));
ããArrayList ResolveList = new ArrayList();
ããfor (int i = 0; i < 10; i++) {
ããResolveList.add(Math.random()* 100);
ãã}
ããfor (int i=0 ;i
ããoutput.write(String.valueOf(ResolveList.get(i)) + â\nâ);
ãã}
ããoutput.close();
ãã} catch (Exception ex) {
ããSystem.out.println(ex);
ãã}
ãã}
ãã}
åæåºèªãæ¯ç¹ç½ãï¼è½¬è½½è¯·ä¿çåæé¾æ¥ï¼
http://soft.chinabyte.com/database/303/12439303.shtml