java檔案操作 java程式設計思想

2021-04-06 20:44:00 字數 1756 閱讀 1992

//這是乙個典型的從檔案讀取然後寫入檔案的方法

file filedir = new file("c://temp//child" + file.separatorchar);

if (!filedir.isdirectory()) else

file fileold = new file(filedir.getpath() + file.separatorchar

+ "buffer.txt");

file file = new file(filedir.getpath() + file.separatorchar

+ "buffer1.txt");

bufferedreader in = new bufferedreader(new filereader(fileold));

printwriter out = new printwriter(new bufferedwriter(new filewriter(file,true)));

int count = 1;

string s;

while((s=in.readline())!=null)

out.close();

//當輸出可供另乙個stream的情況.txt

file filedir = new file("c://temp//child" + file.separatorchar);

if (!filedir.isdirectory()) else

file fileold = new file(filedir.getpath() + file.separatorchar

+ "buffer.txt");

file file = new file(filedir.getpath() + file.separatorchar

+ "buffer1.txt");

dataoutputstream out = new dataoutputstream(new bufferedoutputstream(new fileoutputstream(file)));

out.writedouble(3.14159);

string s = "中國";

out.write(s.getbytes(),0,s.getbytes().length);

//out.writechars("中國this is the value of pi/n");

out.writebytes("this is the value of pi/n");

out.writebytes("this is the value of pi/2/n");

//out.writedouble(3.14159/2);

out.close();

datainputstream in = new datainputstream(new bufferedinputstream(new fileinputstream(file)));

bufferedreader inbr = new bufferedreader(new inputstreamreader(in));

system.out.println(in.readdouble());

system.out.println(inbr.readline());

system.out.println(inbr.readline());

//system.out.println(inbr.readline());

//system.out.println(in.readdouble());

java 檔案操作

複製檔案 param fromfilepath string 目標檔案 param tofilepath string 儲存檔案的路徑 return boolean 複製成功 true 出錯 false public static boolean copyfile string fromfilepa...

java 檔案操作

public class documentutil else else copyfinished this.copyfolder startfile,desfile return copyfinished 顯示目錄下所有檔案ming public static file getdocuments s...

Java 檔案操作

private jfilechooser chooser filenameextensionfilter filter new filenameextensionfilter allowed file txt jar chooser.setfilefilter filter intvalue cho...