sakura_chun 2017-07-20 12:56 采纳率: 0%
浏览 1504

OutputStream的.flush()处理

现在在做一个用java实现 通过telnet来向svn服务器进行交互的程序
private String createRepo() {
//链接服务器
boolean isCon = this.Connent();
if (isCon) {
String com = "svnadmin create C:\svn\repo\123" ;
}
String result = sendCommand(com);
this.disconnect();
}
public String sendCommand(String command) {
try {
writeUtil(command,out);
return readUntil(DEFAULT_AIX_PROMPT,in);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void writeUtil(String cmd, OutputStream out) throws InterruptedException{
try {
cmd = cmd + "\n";
out.write(cmd.getBytes());
out.flush();
//waitForThreeSeconds();
} catch (IOException e) {
e.printStackTrace();
}
}
代码大致是这样,不是全部
然后我发现...直接执行的话是无法实现com这个想新建文件夹的操作的,但是debug的话可以
这样的话应该是直接执行的时候有什么没有完成
查了下发现是out.flush();的问题

上网查了下out.flush();如下,大概的意思就是他可以将字节传递到操作系统进行写入,但它并不保证它们实际上被写入物理设备,如磁盘驱动器。
If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

然后我目前想你的办法是在out.flush();之后用Thread.sleep让他停3秒以上进行处理。。
但是这样做不能保证客户那边百分之百不出错

请问有没有什么可以判断他是否处理完了的方法??还是我有写的不好的地方?
如果有谁知道的请回答~~拜托啦!!谢谢!

  • 写回答

2条回答 默认 最新

  • cloudyzhao 2017-07-21 01:01
    关注

    调用flush 之后 关闭流即可 out.close
    谢谢

    评论

报告相同问题?

悬赏问题

  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算