- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- public class Test6 {
- public static void main(String[] args) throws IOException {
- File a = new File("D:\\试验场");
- File b = new File("D:\\下载");
- show(a,b);
- }
- public static void show(File a,File b) throws IOException {
- File[] a1 = a.listFiles();
- for (File a2 : a1) {
- if (a2.isDirectory()) {
- show(a2,b);
- }
- else if(a2.getAbsolutePath().endsWith(".txt")){
- File c = new File(b,a2.getName().replace(".txt", ".jpg"));
- System.out.println(c.getAbsolutePath());
- c.createNewFile();
- BufferedReader c1 =new BufferedReader(new FileReader(a2));
- BufferedWriter c2 =new BufferedWriter(new FileWriter(c));
- String c3 = "";
- while(!((c3=c1.readLine())==null)){
- c2.write(c3);
- c2.newLine();
- }
- c2.close();
- c1.close();
- }
- }
- }
- }
复制代码 |
|