sakura_chun 2017-07-19 13:44 采纳率: 0%
浏览 1248

关于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 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源
    • ¥15 安卓JNI项目使用lua上的问题
    • ¥20 RL+GNN解决人员排班问题时梯度消失
    • ¥60 要数控稳压电源测试数据
    • ¥15 能帮我写下这个编程吗
    • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路