从服务器读取时找不到文件异常

时间:2014-04-11 10:44:15

标签: java web-services filenotfoundexception

当我从服务器读取文件时,我发现文件未找到异常,但是当我从 main <执行程序时,我可以正常读取文件/ strong>,请告诉我这个问题的建议。 提前致谢。

static Ontology ontology = new SingleFileOntologyImpl("data/Thesaurus_V21.ontology");
        System.err.println("Ontology file read!");

        tokenizerFactory = TokenizerFactoryImpl.createDefaultTokenizerFactory(new UMLSGeneChemTokenizer());

        normalizerFactory = NormalizerFactoryImpl.createDefaultNormalizerFactory(new LVGNormalizer("/home/rajendraprasad.yk/projects/FSTA/FSTA_NLP/tools/lvg2006/data/config/lvg.properties"));
        System.err.println("LVG initialized");

        disambiguator = new TypeDisambiguatorImpl(new RuleDisambiguator[] { new StrictDisambiguator(),new LooseDisambiguator() });
        disambiguationDecisionMaker = new ThresholdDisambiguationDecisionMakerImpl();
        String ontologyLanguageToLoad = null;
        System.out.println(new Date());
        peregrine = new PeregrineImpl(ontology, tokenizerFactory,normalizerFactory, disambiguator,disambiguationDecisionMaker, ontologyLanguageToLoad);
        System.err.println("Peregrine Initialized ! "+ new Date());

例外是:java.lang.RuntimeException: java.io.FileNotFoundException: data/Thesaurus_V21.ontology (No such file or directory)

1 个答案:

答案 0 :(得分:1)

您的服务器显然已将其当前工作目录设置为另一条路径,就像从main运行时的应用程序一样。

如果此文件始终与您的类相关,您可能希望借助类加载器获取文件的路径,请参阅here at stackoverflow

如果这样做无效,您可能需要打印出服务器的当前工作目录(请参阅here at stackoverflow)作为调整路径的帮助。

在服务器配置中有一个相对或绝对路径可能是个好主意。