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

关于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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题