JAVA 讀/寫 文字檔
JAVA 讀/寫 文字檔
//讀文字檔
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
public class test {
public static void main(String [] argv) throws IOException {
FileReader fr = new FileReader(“test.txt”);
BufferedReader br = newBufferedReader(fr);
while (br.ready()) {
System.out.println(br.readLine());
}
fr.close();
}
}
//寫文字檔
import java.io.FileWriter;
import java.io.IOException;
public class test {
public static void main(String [] argv) throws IOException {
FileWriter fw = new FileWriter(“test.txt”);
fw.write(“test”);
fw.flush();
fw.close();
}
}