我是java文件处理的初学者。我厌倦了从我的硬盘分区到我的web应用程序中得到一个bin文件(en解析器-chunking.bin)。到目前为止,我已经尝试了下面的代码,它给我的输出在我的控制台下面。
未知协议:e
这些是我迄今尝试过的代码示例。
//download file
public void download(String url, File destination) throws IOException {
URL website = new URL(url);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
}
public void parserAction() throws Exception {
//InputStream is = new FileInputStream("en-parser-chunking.bin");
File modelFile = new File("en-parser-chunking.bin");
if (!modelFile.exists()) {
System.out.println("Downloading model.");
download("E:\\Final Project\\Softwares and tools\\en-parser-chunking.bin", modelFile);
}
ParserModel model = new ParserModel(modelFile);
Parser parser = ParserFactory.create(model);
Parse topParses[] = ParserTool.parseLine(line, parser, 1);
for (Parse p : topParses){
//p.show();
getNounPhrases(p);
}
}以这种方式获取文件是可能的,还是我做错了?
注意-我要把这个从我的硬盘里拿出来。不是从网上下载的
发布于 2017-06-08 11:22:12
本地文件的正确URL是:
file://E:/Final Project/Softwares and tools/en-parser-chunking.bin其中file是协议。
你也可以:
new File("E:/Final Project/Softwares and tools/en-parser-chunking.bin").toURL() 若要从文件中创建URL,请执行以下操作。
我也重新注释使用斜杠作为文件分隔器,而不是反斜杠。
https://stackoverflow.com/questions/44434285
复制相似问题