我试图在JAVA中生成一个ISO文件,用于在CD上刻录它。在搜索之后,我找到了JIIC(Java Iso Image Creator),它可用on Source Forge或as a Maven dependency。
我创建了一个简单的java类,只生成一个ISO,但我的程序没有正确终止,即它永远不会停止。
public class ISOtest {
private static boolean enableJoliet = true;
private static boolean enableRockRidge = true;
private static boolean enableElTorito = true;
private static void handleOption(String option) {
if (option.equals("disable-joliet")) {
enableJoliet = false;
} else
if (option.equals("disable-rockridge")) {
enableRockRidge = false;
} else
if (option.equals("disable-eltorito")) {
enableElTorito = false;
}
}
public static void main(String[] args) throws Exception {
System.out.println("Start");
// Output file
File outfile = new File(args.length>0 ? args[0] : "ISOTest3.iso");
// Directory hierarchy, starting from the root
ISO9660RootDirectory.MOVED_DIRECTORIES_STORE_NAME = "rr_moved";
ISO9660RootDirectory root = new ISO9660RootDirectory();
if (args.length > 1) {
System.out.println(" If");
// Record specified files and directories
for (int i=1; i<args.length; i++) {
if (args[i].startsWith("--")) {
handleOption(args[i].substring(2, args[i].length()));
} else {
// Add file or directory contents recursively
File file = new File(args[i]);
if (file.exists()) {
if (file.isDirectory()) {
root.addContentsRecursively(file);
} else {
root.addFile(file);
}
}
}
}
} else {
// Record test cases
// Additional test cases
// (file without extension, tar.gz, deeply nested directory;
// sort order tests, renaming tests: filename + extension,
// directory with many files: sector end test)
root.addRecursively(new File("test"));
ISO9660File file1 = new ISO9660File("test/tux.gif", 1);
root.addFile(file1);
ISO9660File file10 = new ISO9660File("test/tux.gif", 10);
root.addFile(file10);
ISO9660File file12 = new ISO9660File("test/tux.gif", 12);
root.addFile(file12);
}
// ISO9660 support
System.out.println("ISO9660 support");
ISO9660Config iso9660Config = new ISO9660Config();
iso9660Config.allowASCII(false);
iso9660Config.setInterchangeLevel(1);
iso9660Config.restrictDirDepthTo8(true);
iso9660Config.setPublisher("Jens Hatlak");
iso9660Config.setVolumeID("ISO Test");
iso9660Config.setDataPreparer("Jens Hatlak");
iso9660Config.setCopyrightFile(new File("Copyright.txt"));
iso9660Config.forceDotDelimiter(true);
RockRidgeConfig rrConfig = null;
if (enableRockRidge) {
// Rock Ridge support
rrConfig = new RockRidgeConfig();
rrConfig.setMkisofsCompatibility(false);
rrConfig.hideMovedDirectoriesStore(true);
rrConfig.forcePortableFilenameCharacterSet(true);
}
JolietConfig jolietConfig = null;
if (enableJoliet) {
// Joliet support
jolietConfig = new JolietConfig();
jolietConfig.setPublisher("Test 1");
jolietConfig.setVolumeID("Joliet Test");
jolietConfig.setDataPreparer("Jens Hatlak");
jolietConfig.setCopyrightFile(new File("Copyright.txt"));
jolietConfig.forceDotDelimiter(true);
}
ElToritoConfig elToritoConfig = null;
if(enableElTorito) {
elToritoConfig = new ElToritoConfig(new File("tomsrtbt-2.0.103.ElTorito.288.img"),
ElToritoConfig.BOOT_MEDIA_TYPE_2_88MEG_DISKETTE,
ElToritoConfig.PLATFORM_ID_X86, "isoTest", 4,
ElToritoConfig.LOAD_SEGMENT_7C0);
}
// Create ISO
System.out.println("Create ISO");
ISOImageFileHandler streamHandler = new ISOImageFileHandler(outfile);
System.out.println("streamHandler");
CreateISO iso = new CreateISO(streamHandler, root);
System.out.println("iso");
iso.process(iso9660Config, rrConfig, jolietConfig, elToritoConfig);
System.out.println("process");
System.out.println("Done. File is: " + outfile);
}
}
在我的控制台中,我有几个System.out.println
Start ISO9660 support Create ISO streamHandler iso
该计划无法实现方法&#34;流程&#34;来自&#34; CreateISO&#34;类。 我的ISO是创建的,但它不能作为存档打开,其大小为0八位字节。
我的错是什么?
调试面板中的堆栈跟踪。
ISO9660Handler(StandardHandler).<init>StreamHandler,ISO9660Directory,StandardConfig) line:35
ISO9660Handler.<init>(StreamHandler, ISO9660RootDirectory, ISO9660Config, RockRidgeConfig) line: 48
CreateISO.process(ISO9660Config, RockRidgeConfig, JolietConfig, ElToritoConfig) line: 57
ISOtest.main(String[]) line: 150
答案 0 :(得分:2)
经过多次测试,我已经禁用了配置参数: - RockRidge - ElTorito
我使用Joliet,配置如下。
我的代码更简单,现在工作正常,我的iso是创建的,我可以用7-zip打开它。
代码:
public class ISOtest {
public static void main(String[] args) throws Exception {
System.out.println("Start");
// Output file
File outfile = new File(args.length>0 ? args[0] : "ISOTest6.iso");
// Directory hierarchy, starting from the root
ISO9660RootDirectory.MOVED_DIRECTORIES_STORE_NAME = "rr_moved";
ISO9660RootDirectory root = new ISO9660RootDirectory();
// Files with different versions
// (to appear in descending order, pointing to same LSN)
ISO9660File file1 = new ISO9660File("test/tux.gif");
root.addFile(file1);
ISO9660File file2 = new ISO9660File("test/150114 Outils.xlsx");
root.addFile(file2);
ISO9660File file3 = new ISO9660File("test/DMD.xlsx");
root.addFile(file3);
// ISO9660 support
System.out.println("ISO9660 support");
ISO9660Config iso9660Config = new ISO9660Config();
iso9660Config.allowASCII(false);
iso9660Config.setInterchangeLevel(1);
iso9660Config.restrictDirDepthTo8(true);
iso9660Config.setPublisher("Name Nickname");
iso9660Config.setVolumeID("ISO Test Jiic");
iso9660Config.setDataPreparer("Name Nickname");
//iso9660Config.setCopyrightFile(new File("Copyright.txt"));
iso9660Config.forceDotDelimiter(true);
RockRidgeConfig rrConfig = null;
ElToritoConfig elToritoConfig = null;
JolietConfig jolietConfig = null;
// Joliet support
System.out.println("Joliet support");
jolietConfig = new JolietConfig();
jolietConfig.setPublisher("Test 2");
jolietConfig.setVolumeID("Joliet Test");
jolietConfig.setDataPreparer("Jens Hatlak");
//jolietConfig.setCopyrightFile(new File("Copyright.txt"));
jolietConfig.forceDotDelimiter(true);
System.out.println("Create ISO");
ISOImageFileHandler streamHandler = new ISOImageFileHandler(outfile);
System.out.println("streamHandler");
CreateISO iso = new CreateISO(streamHandler, root);
System.out.println("iso");
iso.process(iso9660Config, rrConfig, jolietConfig, elToritoConfig);
System.out.println("process");
System.out.println("Done. File is: " + outfile);
}
}