使用Java读取远程文件 [英] Reading a remote file using Java

查看:1504
本文介绍了使用Java读取远程文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种简单的方法来获取位于远程服务器上的文件.为此,我在Windows XP上创建了本地ftp服务器,现在我想为测试Applet提供以下地址:

I am looking for an easy way to get files that are situated on a remote server. For this I created a local ftp server on my Windows XP, and now I am trying to give my test applet the following address:

try
{
    uri = new URI("ftp://localhost/myTest/test.mid");
    File midiFile = new File(uri);
}
catch (Exception ex)
{
}

当然,我会收到以下错误消息:

and of course I receive the following error:

URI方案不是文件"

URI scheme is not "file"

我一直在尝试其他方法来获取文件,但它们似乎没有用.我该怎么办? (我也很想执行HTTP请求)

I've been trying some other ways to get the file, they don't seem to work. How should I do it? (I am also keen to perform an HTTP request)

推荐答案

使用ftp不能立即使用.

You can't do this out of the box with ftp.

如果文件位于http上,则可以执行以下操作:

If your file is on http, you could do something similar to:

URL url = new URL("http://q.com/test.mid");
InputStream is = url.openStream();
// Read from is

如果要使用库进行FTP,则应签出 Apache Commons Net

If you want to use a library for doing FTP, you should check out Apache Commons Net

这篇关于使用Java读取远程文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆