【发布时间】:2018-05-21 10:12:49
【问题描述】:
对于一个重要的项目,我正在尝试使用第三方库JLR来导出格式化的PDF报告。
这一直正常工作,直到两天前,当悬停在我用作 NetBeans IDE 文件查看器中报告模板的 .tex 文件上时,会显示一个工具提示,将文件表示为“无法识别的文件”。它也将不再作为资源导入,因为当使用类的getResource 方法或其ClassLoader.getResource 方法时,生成的File 对象不存在。我的工作目录中的所有内容都在适当的位置,并通过相对文件路径引用它。
- 这是什么意思?
- 如何让文件被识别?
- 我可以防止这种文件类型再次发生吗?
编辑:我尝试更改 NetBeans 与文件关联的 MIME 类型,以查看 NetBeans 是否识别它,但这没有成功。
编辑:如果有人想看,这是相关代码。
public Boolean createAndFormatLaTex(String nameOfExercise, String author, String date, String desc, List<Rule> rulesToPrint) {
Boolean success = true;
gen = new JLRGenerator();
try {
ClassLoader cl = this.getClass().getClassLoader();
URL templateLoc = cl.getResource("resources/templateRep.tex");
File templateFile = new File(templateLoc.getFile());
//URL workDirLoc = cl.getResource(System.getProperty("user.home")+File.separator+"MaMoOr"+File.separator+"resources"+File.separator);
File workDir = new File(System.getProperty("user.home")+File.separator+"MaMoOr"+File.separator+"resources"+File.separator);
//URL tempDirLoc = cl.getResource(System.getProperty("user.home")+File.separator+"MaMoOr"+File.separator+"resources"+File.separator+"temp"+File.separator);
File tempDir = new File(System.getProperty("user.home")+File.separator+"MaMoOr"+File.separator+"resources"+File.separator+"temp"+File.separator);
File reptemp1 = new File(tempDir.getAbsolutePath() + File.separator + nameOfExercise+"-report.tex");
String s = templateFile.getAbsolutePath();
templateFile.setReadable(true);
conv = new JLRConverter(workDir);
conv.replace("date", date);
conv.replace("description", desc);
conv.replace("authorName", author);
conv.replace("nameOfExercise", nameOfExercise);
conv.replace("rulesToPrint", rulesToPrint);
if (!conv.parse(templateFile, reptemp1)) {
success = false;
}
File desktop = new File(System.getProperty("user.home") + File.separator + "Desktop");
if(!gen.generate(reptemp1, desktop ,workDir))
{
success = false;
}
reptemp1.deleteOnExit();
tempDir.deleteOnExit();
} catch (IOException iex) {
System.out.println(iex.getMessage());
return false;
//} catch (URISyntaxException ex) {
// Logger.getLogger(LaTexParser.class.getName()).log(Level.SEVERE, null, ex);
// return false;
}catch(NullPointerException nex){
Logger.getLogger(LaTexParser.class.getName()).log(Level.SEVERE, null, nex);
return false;
}
return success;
}
【问题讨论】:
-
上传您的代码
-
@Adya 问题不在于代码,因为它之前已经运行过,并且自上次运行以来我没有对其进行任何更改。我有理由相信是 IDE 或 JVM 导致了问题。我尝试更改 MIME 类型以查看 NeBeans 是否识别它,但无济于事。还是添加了代码。
标签: java netbeans latex typesetting