IOException将数据加载到BlazegraphEmbedded中

时间:2017-03-09 20:02:58

标签: java tinkerpop3 blazegraph

我在将Blazegraph属性文件加载到嵌入式实例时遇到问题。当我尝试将 .properties 文件导入我的Java类时,出现以下错误:

Exception in thread "main" java.io.IOException: Stream closed
at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.Reader.read(Unknown Source)
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at blazegraph_tinkerpop_tryout.blazegraph_data_load.loadProperties(blazegraph_data_load.java:55)
at blazegraph_tinkerpop_tryout.blazegraph_data_load.main(blazegraph_data_load.java:32)

从main:

调用loadProperties函数
Properties props = loadProperties("sampleprops.properties");

我的loadProperties函数(检查文件路径是否有效,然后发送给读者):

public static Properties loadProperties(String resource) throws IOException 
{
    Properties p = new Properties();
    Path path = Paths.get(resource);
    Boolean bool = Files.exists(path);
    if (bool)
    {
        System.out.println("File was found. Attempting data load...");
        InputStream is = blazegraph_data_load.class.getResourceAsStream(resource);
        p.load(new InputStreamReader(new BufferedInputStream(is)));
        return p;
    }
    System.out.println("The file you entered was not found.");
    return null;
}

以下是我的文件 sampleprops.properties 的样子:

com.bigdata.journal.AbstractJournal.bufferMode=DiskRW
com.bigdata.journal.AbstractJournal.file=blazegraph.jnl

我一直在按照here描述的示例Blazegraph应用程序中的设置说明进行操作。如果它有所作为,我正在使用找到here的Blazegraph / Tinkerpop3实现。

1 个答案:

答案 0 :(得分:0)

我找到了解决方法:我将getResourceAsStream方法切换为FileInputStream方法。

问题出在我的属性文件的位置上。 FileInputStream方法在您放置文件的位置似乎更宽容。