FileTest.java 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import org.junit.Test;
  2. import java.io.File;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.io.PrintWriter;
  6. /**
  7. * Created by raodeming on 2021/7/2.
  8. */
  9. public class FileTest {
  10. @Test
  11. public void test1() throws IOException {
  12. String sql = "INSERT INTO `aj_report`.`gaea_file` (`id`, `file_id`, `file_type`, `file_path`, `url_path`, `file_instruction`, `create_by`, `create_time`, `update_by`, `update_time`, `version`) VALUES (default, '%s', 'png', '/app/aj-report/image/%s', 'https://report.anji-plus.com/file/download/%s', '%s', 'admin', '2021-07-02 10:04:55', 'admin', '2021-07-02 10:04:55', '1');\n";
  13. File paFile = new File("D:\\anji\\盖亚\\大屏设计\\png");
  14. PrintWriter pw = new PrintWriter(new FileWriter("D:\\anji\\盖亚\\大屏设计\\fileSql.sql", true));
  15. File[] files = paFile.listFiles();
  16. for (File file : files) {
  17. String name = file.getName();
  18. String fileName = name.split("\\.")[0];
  19. //System.out.println(fileName);
  20. String format = String.format(sql, fileName, name, fileName, fileName);
  21. System.out.println(format);
  22. pw.print(format);
  23. }
  24. pw.flush();
  25. pw.close();
  26. }
  27. }