import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class TextFileCopy {
public static void main(String[] args) {
FileReader reader = null;
FileWriter writer = null;
try {
// 建立檔案輸入輸出流
reader = new FileReader("F:\\電子文檔\\各種JDBC連接配接.txt");
writer = new FileWriter("F:\\test.txt");
int flag = 0;
// 從輸入流讀取内容使用輸出流輸出
while ((flag = reader.read()) != -1) {
writer.write(flag);
}
System.out.println("複制文本成功");
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close(); // 關閉檔案輸入流
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (writer != null) {
try {
writer.close(); // 關閉檔案輸出流
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}