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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料