Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java中使用vi编辑器编辑文件_Java_Vi - Fatal编程技术网

在java中使用vi编辑器编辑文件

在java中使用vi编辑器编辑文件,java,vi,Java,Vi,我正在写一个程序,我需要远程登录到远程机器,访问一个文件并编辑它。 我能做telnet部分。 这使我能够访问该系统的OutputStream和InputStream。我可以发送命令并使用vi编辑器打开文件。我也能阅读文件的内容 DataInputStream data = new DataInputStream(telnet.getInputStream()); data.readLine(). 但我无法写入或编辑此文件。 有什么建议吗?我怀疑您在远程系统上遇到了行编辑问题。我认为使用sed(

我正在写一个程序,我需要远程登录到远程机器,访问一个文件并编辑它。 我能做telnet部分。 这使我能够访问该系统的OutputStream和InputStream。我可以发送命令并使用vi编辑器打开文件。我也能阅读文件的内容

DataInputStream data = new DataInputStream(telnet.getInputStream());
data.readLine().
但我无法写入或编辑此文件。
有什么建议吗?

我怀疑您在远程系统上遇到了行编辑问题。我认为使用
sed
(正如@Jim Garrison提到的)或使用基于行的
ed
编辑器将取代vi或emacs等基于键的编辑器

下面是一个如何使用ed编辑名为“file”的文件的快速示例<代码>人工编码应显示各种功能

> ed file
file: No such file or directory
i
hello there
.
1
hello there
a
and now append a line
.
1,$n
1       hello there
2       and now append a line
w
34
q

> cat file
hello there
and now append a line

不使用vi,您能用
sed
脚本表达您需要做什么吗?这将消除在屏幕上导航的需要。远程计算机中的用户是否具有写入文件的权限?您在telnet中使用哪种api?我怀疑您不能使用
vi
,因为它是一个可视命令,与设备键盘交互,而不是
stdin
/
stdout
。如何提供修改?我使用的是apache-commons.net API。我能读vi,但我不能写进去。我也有权写它。