怎样才能显示ICEfaces的Java文件复制操作的进展如何? [英] How does one show progress of a Java file copy operation in ICEfaces?

查看:126
本文介绍了怎样才能显示ICEfaces的Java文件复制操作的进展如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要执行文件复制操作,并显示用户的进度条的ICEfaces的Web应用程序。

I have an ICEfaces web application which needs to perform a file copy operation and show user a progress bar.

目前,该副本是由调用'的cpio',这不能给到Java code进度,直至操作完成后进行。虽然有可能用Java编写的监测与读取的复制进度的估计字节数字节数,我觉得可能是一个简单的解决方案,如果我code Java中的实际复制操作。我仍然会使用'cpio'可以用于存档的目的,但实际副本会被Java类中进行。

Currently, the copy is being done by calling 'cpio' which cannot give progress to the Java code until after the operation has completed. While it would be possible to use Java to monitor the number of bytes written vs. number of bytes read for an estimate of the copy progress, I think there might be a simpler solution if I code the actual copy operation in Java. I would still use 'cpio' for archiving purposes, but the actual copy would be performed by a Java class.

大部分我在搜索中发现的帮助下与progressMonitor,它采用了Swing组件,而我不知道它可以做我想做的。所有我需要的是的,我可以养活我的JSF进度条组件作为%满分100进度的整数/双。

Most of the help I found in my searching was related to progressMonitor, which incorporates a swing component, and I'm not sure that it can do what I want. All I need is an integer/double of the progress which I can feed to my JSF progress bar component as a % out of 100.

推荐答案

我不知道ICEFaces的,但这里是如何将文件在Java中复制和显示器上的命令行进展情况:

I don't know about ICEFaces but here is how to copy a file in java and monitor progress on the commandline:

import java.io.*;

public class FileCopyProgress {
    public static void main(String[] args) {
        System.out.println("copying file");
        File filein  = new File("test.big");
        File fileout = new File("test_out.big");
        FileInputStream  fin  = null;
        FileOutputStream fout = null;
        long length  = filein.length();
        long counter = 0;
        int r = 0;
        byte[] b = new byte[1024];
        try {
                fin  = new FileInputStream(filein);
                fout = new FileOutputStream(fileout);
                while( (r = fin.read(b)) != -1) {
                        counter += r;
                        System.out.println( 1.0 * counter / length );
                        fout.write(b, 0, r);
                }
        }
        catch(Exception e){
                System.out.println("foo");
        }
    }
}

您将不得不以某种方式更新进度条而不是的System.out.println()
我希望这可以帮助,但也许我不明白你的问题。

You would have to somehow update your progress bar instead of the System.out.println(). I hope this helps, but maybe i did not understand your question.

这篇关于怎样才能显示ICEfaces的Java文件复制操作的进展如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆