package kao.chih.chien.test;
import java.io.FileWriter;
import java.io.IOException;
public class WriterTest {
static String WRITER_TEST_PATH = "C:\\Test.txt";
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
FileWriter fw = new FileWriter(WRITER_TEST_PATH,true);
fw.write("\tHello");
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package kao.chih.chien.test;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class ReadTest {
static String READ_TEST_PATH = "C:\\Test.txt";
static char data[] = new char[1024];
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
FileReader fr = new FileReader(READ_TEST_PATH);
int num = fr.read(data);
String s = new String(data, 0, num);
System.out.println(s);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
沒有留言:
張貼留言