如何使用java从远程系统读取文件? [英] How to read a file from remote system using java?

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

问题描述

我在一台计算机上复制了一个文件,我需要从其他计算机访问该文件。
我不确定,使用哪种协议或哪种技术?
请为我提供任何提示..

I have a file copied in one computer and I need to access the file from other computer. I am not sure, which protocol or which technology to use for this? Please provide me any hints for this..

我使用的是Ubuntu Linux系统。
我使用的代码:

I am using Ubuntu Linux system. I used the code :

File f = new File("//192.168.1.157/home/renjith/picture.jpg");// 192.168.1.157 is the ip of the computer, where I have the picture file
Image image = ImageIO.read(f);

但它是一个例外:

javax.imageio.IIOException: Can't read input file!
    at javax.imageio.ImageIO.read(ImageIO.java:1275)

我有共享renjith文件夹。

I have shared renjith folder also.

推荐答案

有多种方法可以访问远程计算机上的文件,但它们几乎都依赖于已经设置了远程机器以首先以某种方式提供文件。如果您要通过java访问文件,最简单的方法可能是在远程计算机上设置HTTP服务器(这可以通过各种平台上的Apache HTTP服务器轻松完成),然后使用Apache Commons HTTPClient客户端Java应用程序。关于如何安装这些或配置它们的进一步讨论通常超出了Stack Overflow的范围,并且至少需要一个更具体的问题

There are any number of ways to access files on remote machines, but they virtually all depend on the remote machine having been set up to provide the file in some way first. If you with to access files via java, the easiest method would probably be to set up an HTTP server on the remote machine (this can be done pretty easily using Apache HTTP server on a variety of platforms) and then using Apache Commons HTTPClient on the client side java app. Further discussion of how to install these or configure them is generally beyond the scope of Stack Overflow and would at least require a more specific question

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

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