sakura_chun 2017-07-19 14:52 采纳率: 0%
浏览 3179

关于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秒以上进行处理。。
但是这样做不能保证客户那边百分之百不出错

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 spring后端vue前端
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题