package com.dtxytech.account.generate;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
public class SqlFileGenerate {
static String globalPath = "D:/plsql";//sql脚本所在路径
static String localPath = "D:\\plsql\\";//sql脚本所在路径
static String fileName = "init.sql";//产生的sql脚本文件
static String logfileName = "init.log";//产生的日志文件
static String split = "/";
static File myFile;
static Writer write;
static long fileUpdateDate = LocalDateTime.of(2022, 5, 5, 11, 0).
toInstant(ZoneOffset.ofHours(+8)).toEpochMilli();//这个日期以后修改文件
public static void main(String[] args) throws Exception {
myFile = new File(globalPath + split + fileName);
if (!myFile.exists())
myFile.createNewFile();
write = new OutputStreamWriter(new FileOutputStream(myFile), StandardCharsets.UTF_8);
write.write("spool " + logfileName+"\n");
write.write("set define off;\n");
getFileName(globalPath);
write.write("set define off;\n" +
"prompt 结束;\n");
write.write("spool off");
write.flush();
write.close();
}
public static void getFileName(String path) throws IOException {
String tempPath;
File f = new File(path);
if (!f.exists()) {
System.out.println(path + " not exists");
return;
}
File fa[] = f.listFiles();
for (int i = 0; i < fa.length; i++) {//循环遍历
File fs = fa[i];//获取数组中的第i个
String name = fs.getName();
if (fs.isDirectory()) {
tempPath = path + split + name;
getFileName(tempPath);
} else if (!path.equals(globalPath) && (name.toLowerCase().endsWith(".sql")
|| name.toLowerCase().endsWith(".pck")
|| name.toLowerCase().endsWith(".trg")
)
&& fs.lastModified() > fileUpdateDate
) {
write.write("prompt Creating " + name+"\n");
write.write("prompt ================================"+"\n");
write.write("@@" + fs.getCanonicalPath().replace(localPath, "")+"\n");
}
}
}
}
06-04
912
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-29
08-29
351
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-31
478
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-28
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交