package tool;
import java.io.File;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.List;
public class ModifyOracleVersion {
public static void main(String[] args) {
//将文件夹下11g的dmp文件改为10g
String dir = "D:\\dmp";
List<String> fileNameList = getAllFile(dir,false);
for (int i = 0; i < fileNameList.size(); i++) {
oracle11gTo10g(fileNameList.get(i));
}
//单个文件修改
//oracle11gTo10g("D:\\exp0902\\acf_app_sm.dmp");
}
public static void oracle11gTo10g(String fileName) {
try {
RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
byte b[] = new byte[50];
raf.read(b);
for (int i = 0; i < b.length; i++) {
System.out.print(b[i] + ",");
}
//这个是修改成10g:V10.02.01。如果在修改前自己可以截出头部的几个字节确认一下,是不是就是修改第12,18字节
b[12] = 48;
b[18] = 49;
raf.seek(0);
raf.write(b);
raf.close();
System.out.println("");
} catch (Exception ex) {
} finally {
}
}
/**
* 遍历文件夹
* @param path
* @param list
*/
public void traverseFolder(String path,List<String> list) {
File file = new File(path);
if (file.exists()) {
File[] files = file.listFiles();
if (files.length == 0) {
System.out.println("文件夹是空的!");
return;
} else {
for (File file2 : files) {
if (file2.isDirectory()) {
System.out.println("文件夹:" + file2.getAbsolutePath());
traverseFolder(file2.getAbsolutePath(),list);
} else {
System.out.println("文件:" + file2.getAbsolutePath());
list.add(file2.getAbsolutePath());
}
}
}
} else {
System.out.println("文件不存在!");
}
}
/**
* 获取路径下的所有文件/文件夹
* @param directoryPath 需要遍历的文件夹路径
* @param isAddDirectory 是否将子文件夹的路径也添加到list集合中
* @return
*/
public static List<String> getAllFile(String directoryPath,boolean isAddDirectory) {
List<String> list = new ArrayList<String>();
File baseFile = new File(directoryPath);
if (baseFile.isFile() || !baseFile.exists()) {
return list;
}
File[] files = baseFile.listFiles();
for (File file : files) {
if (file.isDirectory()) {
if(isAddDirectory){
list.add(file.getAbsolutePath());
}
list.addAll(getAllFile(file.getAbsolutePath(),isAddDirectory));
} else {
list.add(file.getAbsolutePath());
}
}
return list;
}
}
Oracle11g的dmp数据文件改为10g
最新推荐文章于 2021-12-15 18:10:48 发布