1

我在网络路径中有一个 wav 文件,我可以从该文件夹中以 \192.106.100.35\Recorded 文件的身份运行访问它,我必须访问 536.wav 文件,我试过

代码

File file = new File("file://192.106.100.35/Recorded%20files/536.wav");
    FileInputStream fis;
    byte[] buffer=null;

fis = new FileInputStream(file);
buffer= new byte[fis.available()];
fis.read(buffer);
fis.close();

但给

java.io.FileNotFoundException: file:\192.106.100.35\Recorded%20files\536.wav (The filename, directory name, or volume label syntax is incorrect)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at com.pointel.chart.PlayAudio.doGet(PlayAudio.java:39)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)
Oct 31, 2013 5:51:02 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet PlayAudio threw exception
java.lang.NullPointerException
    at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:83)
    at com.pointel.chart.PlayAudio.doGet(PlayAudio.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)

任何帮助表示赞赏

4

2 回答 2

1

java.io.File仅适用于本地硬盘。java.net.URL改为用于网络资源:

new URL("http://192.106.100.35/Recorded%20files/536.wav");

为此,您需要一个192.106.100.35支持 HTTP 协议并将文件公开为的服务器/Recorded%20files/536.wav

其他选项是 NFS 或 SMB(在本地计算机上安装远程文件系统;之后,您可以File再次使用)。

于 2013-10-31T12:46:27.277 回答
0

简短的版本是你根本不能这样做。

Javadoc here 我猜这可能是 Windows 共享?但是你如何得到它取决于服务器端。如果您实际上可以安装远程设备,例如(NFS/Samba/CIFS),那么您可以挽救这种方法。但是,如果它就像一个 HTTP 服务器,那么你就完全找错了树。

于 2013-10-31T12:45:41.103 回答