2018年11月9日 星期五

[Java]_ch13.1_文字檔讀取與寫入



[Java]_ch13.1_文字檔讀取與寫入

package YPU;



import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;



public class A13 {



public static void main(String[] args) throws IOException {

FileReader fr;

try {

fr=new FileReader("C:\\Gjun135\\A20181109.txt");

} catch (FileNotFoundException e) {

fr=new FileReader("C:\\CCTU135\\B20181109.txt");

System.out.println("e="+e);

}

char data[]=new char[512];

int num=fr.read(data);

System.out.print("總共讀取:"+num+"字元\n");

for(int i=0;i<data.length;i++){

System.out.print(data[i]);

}

String s1=new String(data,0,num);

System.out.println("\ns1.length="+s1.length());

System.out.println(s1);

System.out.println("\n讀取結束....");

FileWriter fw=new FileWriter("C:\\Gjun135\\C20181109.txt",true);

fw.write(s1);

fr.close();

fw.close();

}



}


沒有留言:

張貼留言

Ether.fi Cash Card 一張所有人必備的加密貨幣信用卡   [Ether.fi Cash Card] : https://www.ether.fi/app/cash/sign-up?ref_code=d27f8523 ------國際交易所------ [Bitg...