是否可以从远程服务器连续获取文件内容 [英] Is that possible to get file content continuously from remote server

查看:41
本文介绍了是否可以从远程服务器连续获取文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在本地可以逐行获取文件内容.就像

I know locally it is possible to get file content line by line. just like

Scanner s = new Scanner(new File("D:\\Users\\qding\\Desktop\\spy.log"));
    while (s.hasNextLine()) {
        String line = s.nextLine();
        System.out.println("[Method Server] " + line);
}

是否可以从远程(Windows/Linux)获取文件内容?

Is it possible to get file content from remote (Windows/Linux)?

此外,在远程文件中,该文件是一个日志文件,并且始终会更新.所以第二个问题是是否可以连续归档内容(多线程?)?

Also, on the remote, the file was a log file, and it is updated always. So the second question is if is possible to file content continuously (with multiple thread?)?

推荐答案

A1.是的,可以从远程系统获取文件内容,前提是它可以通过任何协议访问.

A1. Yes it is possible to get file content from remote system, provided it is accessible over any protocol.

A2.在 unix 系统上,要读取不断变化的文件的内容,我们有 tail -f ... 命令.请参阅文件监控.要通过网络读取此类文件,您肯定需要 Threads 的帮助来等待和读取更新.Apache commons 有自定义 tail 可能对您有所帮助的实现.

A2. On unix systems, to read content of a file that is changing continuously, we have tail -f ... command. Please refer to File Monitoring. And to read such files over network, you definitely require help of Threads to wait and read the updates. Apache commons has custom tail implementations that may help you.

你可以参考一个类似的帖子 关于 SO,以获取详细的建议和讨论.

You can refer to a similar posting on SO, for detailed suggestions and discussions.

更新:
A2:对于 Windows,有第三方 GUI 工具 Tail for Win32,但我从来没有做过.
您还可以在 Windows ... 相当于tail-f"?.

Update:
A2: For windows, there is a third party GUI tool Tail for Win32, but never I worked on it.
You can also refer to some more suggestions at Windows ... equivalent of "tail -f"?.

这篇关于是否可以从远程服务器连续获取文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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