當前位置:成語大全網 - 書法字典 - 如何用java讀取壹個txt文件的內容,創建壹個新的txt文件並保存內容?

如何用java讀取壹個txt文件的內容,創建壹個新的txt文件並保存內容?

公共靜態void main(String【】args)引發IOException,

ClassNotFoundException {

嘗試{

file InputStream in = new file InputStream(//創建輸入流。

“E:\ \ 0326 Java \ \ javase \ \ src \ \ io \ \ testfile inputstream . Java“);

FileOutputStream out = new file outputstream(“E:\ \ 1 . txt“);//創建輸出流

int I = 0;

while((I = in . read())!= -1) {

system . out . print((char)I);//循環讀取文件數據

out.write(我);//將每個讀取的數據輸入1.txt

}

out . flush();

out . close();

} catch(file not found exception e ){

// TODO自動生成的catch塊

e . printstacktrace();

} catch(io exception e ){

// TODO自動生成的catch塊

e . printstacktrace();

}

}