IOException 将数据加载到 BlazegraphEmbedded
IOException Loading Data into BlazegraphEmbedded
我在将 Blazegraph 属性文件加载到嵌入式实例时遇到问题。当我尝试将 .properties 文件导入 Java class 时,出现以下错误:
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)
从主函数调用 loadProperties
函数:
Properties props = loadProperties("sampleprops.properties");
我的loadProperties
函数(检查文件路径是否有效,然后发送到reader):
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. If it makes a difference, I am using the Blazegraph/Tinkerpop3 implementation found here.
中描述的示例 Blazegraph 应用程序中的设置说明进行操作
我找到了解决方法:我将 getResourceAsStream
方法切换为 FileInputStream
方法。
问题出在我的属性文件的位置上。 FileInputStream
方法在放置文件的位置上似乎更宽容。
我在将 Blazegraph 属性文件加载到嵌入式实例时遇到问题。当我尝试将 .properties 文件导入 Java class 时,出现以下错误:
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)
从主函数调用 loadProperties
函数:
Properties props = loadProperties("sampleprops.properties");
我的loadProperties
函数(检查文件路径是否有效,然后发送到reader):
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. If it makes a difference, I am using the Blazegraph/Tinkerpop3 implementation found here.
中描述的示例 Blazegraph 应用程序中的设置说明进行操作我找到了解决方法:我将 getResourceAsStream
方法切换为 FileInputStream
方法。
问题出在我的属性文件的位置上。 FileInputStream
方法在放置文件的位置上似乎更宽容。