不打开revit判断rvt版本
上次是用程序直接读取rvt,来判断
还有一种方法,使用解压软件解压到文件夹,目录结构为
其中rvt的版本在BasicFileInfo中
使用Java来判断
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RevitVersion { public static void main(String[] args) { String fileName = "E:\\test\\BasicFileInfo"; String version = rvtVersion(fileName); System.out.println(version); } public static String rvtVersion(String fileName) { File file = new File(fileName); System.out.println("fileName:" + fileName); BufferedReader reader = null; String version = ""; String MatchVersion = "((?<=Autodesk Revit )\\d{4})"; String finalStr =""; try { System.out.println("以行为单位读取文件内容,一次读一整行:"); reader = new BufferedReader(new FileReader(file)); String tempString = null; int line = 1; // 一次读入一行,直到读入null为文件结束 while ((tempString = reader.readLine()) != null) { char[] strArr = tempString.toCharArray(); //处理特殊字符 for (int j = 0; j < strArr.length; j++) { if ((int) strArr[j] == 0) { strArr[j] = '*'; } } finalStr = String.valueOf(strArr); finalStr = finalStr.replace("*", ""); Pattern pattern = Pattern.compile(MatchVersion); Matcher match = pattern.matcher(finalStr); if (match.find()) { version = match.group(1); break; } line++; } // 显示行号 System.out.println("line " + line+ ": " + finalStr); reader.close(); return version; } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e1) { } } } return version; } }
https://sourceforge.net/projects/openmcdf/files/