2017-06-08 25 views
0

我是初學java文件處理。我厭倦了從我的硬盤分區獲取bin文件(en-parser-chunking.bin)到我的web應用程序。到目前爲止,我已經嘗試了下面的代碼,它給了我下面我的控制檯的輸出。java未知協議: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); 
    } 
} 

得到這樣一個文件是可能的,或者我已經做錯了?

注 - 我需要從我的硬盤上得到這個。不從互聯網

回答

2

下載正確的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。

我也是電子書籍使用斜線爲反斜線

+0

代替這給了我下面的輸出文件分隔符「下載模式 連接超時:連接」 – user8048032