Netbeans无法识别.tex文件

时间:2018-05-21 10:12:50

标签: java netbeans latex typesetting

对于一个重要项目,我正在尝试使用第三方库JLR导出格式化的PDF报告。

直到两天前,这已经正常工作,当鼠标悬停在我用作NetBeans IDE文件查看器中的报表模板的.tex文件时,会显示一个工具提示,指示该文件为“无法识别的文件”。它也将不再作为资源导入,因为使用类的getResource方法或其ClassLoader.getResource方法时,生成的File对象不存在。我将所有内容放在工作目录中的适当位置,并通过相对文件路径引用它。

  1. 这是什么意思?
  2. 如何才能识别文件?
  3. 我可以使用此文件类型阻止这种情况再次发生吗?
  4. 编辑:我尝试更改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;
    }
    

1 个答案:

答案 0 :(得分:0)

好的,所以我从其他人那里汇总了解决方案,而那个有效的解决方案是将资源读作InputStream而不是File

这看起来像这样:

ClassLoader cl = this.getClass().getClassLoader();

        InputStream is = cl.getResourceAsStream("resources/templateRep.tex");
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        //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");
        File tempStorageFile = new File(tempDir.getAbsolutePath() + File.separator + "tempStorage.tex");

        OutputStream os = new FileOutputStream(tempStorageFile);
        IOUtils.copyLarge(is, os);
        os.close();

替换

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();

在原始代码中。