File Copy With JProgressBar

Hi i'm using the below code to copy a file and display the progress on screen. However the file copies ok by the progressbar is never shown. Can somebody please show me how to use the JProgressBar Component to copy a file and show the progress?
Thanks
Arlef
public void copyFileToMediaFolder(File f){
String newFileName = f.getName();
try{
File inputFile = f.getAbsoluteFile();
int fSize = (int)f.length();
FileCopyProgress fcp = new FileCopyProgress(this,true);
File outputFile = new File(mediaFolder + File.separatorChar + newFileName);
FileInputStream in = new FileInputStream(inputFile);
FileOutputStream out = new FileOutputStream(outputFile);
int c;
int bytesRead = 0;
int counter = 0;
while ((c = in.read()) != -1){
out.write(c);
counter = counter + 1;
bytesRead = fSize / 100 * counter;
in.close();
out.close();
fcp.dispose();
}catch(Exception ex){
//System.out.println("nEW FILE NAME = "+newFileName);
}

The progressbar is in a JDialog and is represented in
the following line in the code i sent earlier
FileCopyProgress fcp = new FileCopyProgress(this,true);Yes, i'm aware of that, but what I'm saying is that you don't seem to be updating the status of the progressbar while copying the file...I suppose the progressbar would start with 0 or 0% and then there should be some functions to be called to make it "progress" to 10..20...50..60% etc... So I believe you should call such a function from inside the loop where the file is being copied...I remember it used to be like that in Visual C++, so i'm supposing the behavior is similar in Java.
Good luck :)
Talal

Similar Messages

  • File Copy with resume enable

    I am thinking of making a file copy program like the download managers, which provides resume enables, so that users can continue at later times.
    Suppose, i have a 10 GB file, and i want to transfer it over to my external, then instead of non breakable file copying, user get the option to stop, and resume laters from that point only.
    I am not sure if its feasible in java, but if its, please tell me how to achieve that.
    I am not asking you to give me the code, rather a bit about how to proceed in that direction.
    Thank you.

    user7761515 wrote:
    I am thinking of making a file copy program like the download managers, which provides resume enables, so that users can continue at later times.Well, I suspect you're going to have to come up with some sort of protocol that allows your copy job to complete its task (eg, a separate file containing the number of bytes written to the "partial" so that it knows where to resume from). I'd also suggest that you use some sort of name extension to distinguish your partial from a completed file, and only rename it when you know the job is finished.
    Alternatively, you could create "chunks" for each portion copied between a start/resume and the next pause (maybe with numbered extensions) and then concatenate them together as a final step (possibly simpler, but likely less efficient in space and time).
    Another thing to think about is changes: What if someone changes the file you want to copy between the time you pause and the time you resume? I suspect it should invalidate the whole job, but you'll probably want to check modification times (or alternatively, use a checksum) before you resume.
    If this is just an exercise, great; otherwise I suspect you may be re-inventing the wheel.
    Winston
    Edited by: YoungWinston on Nov 13, 2010 12:02 PM
    It also occurs to me that you might want to investigate FTP. I'm pretty sure it has hooks for pausing and resuming, but you'll probably have to check if the Java library you choose allows that capability.

  • File copy with change of file type

    I'm currently working on what seems like a simple file-to-file scenario. A file (without an extension) on server A has to be copied to server B. The name of the file on the target server should be the same as the file on the source system. Only change is that the file on the target system should get a .txt extension. After trying various options I'm stuck on the .txt extension.
    I enabled File Name in Adapter Specific Message Properties on both the sender and receiver communication channels. With this option the file gets copied to the target server with the same name, but I cannot add the .txt extension. I also followed the instructions in this blog: https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/2664. [original link is broken] [original link is broken] [original link is broken] Unfortunately, I don't see the file name in the payload of my message, which means I cannot use it in the Variable Substitution option of my receiver communication channel.
    Does anyone know what I might be doing wrong here?
    Edited by: Cheese2 on Jul 15, 2009 12:39 PM

    use dynamic configuration. you can manipulate the file names very easily - /people/shabarish.vijayakumar/blog/2009/03/26/dynamic-configuration-vs-variable-substitution--the-ultimate-battle-for-the-file-name
    /people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14 - in your case as per this blog all you need to change in the code will be;
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    String ourSourceFileName = conf.get(key);
    ourSourceFileName = ourSourceFileName + ".txt";
    return  ourSourceFileName;

  • Creating a control file copy with ASM

    Configuration is Oracle 10.2, RAC, and ASM (Automatic Storage Management). I would like to create a second copy of the control file.
    If this wasn't ASM, I could just bring down the database, copy the control file using an operating system command, modify the pfile to reference both the original and new copy, and then restart the database.
    Since this is ASM, I cannot use an operating system command to copy the control file, and RMAN "BACKUP" (which is the only way I know to make a copy of the control file) will only work if the database is up. When I "restore" the control file using RMAN and change the pfile to reference both control files I get a message like the following when attempting to start the database:
    ORA-00214: control file '+ASMGROUP1/db1/controlfile/current.271.566646845'
    version 2241 inconsistent with file
    '+ASMGROUP1/db1/controlfile/current.268.566661765' version 2236
    Soooooo, how do I make and implement a second copy of a control file using ASM.
    Thanks

    Hi.
    This is not testet so presede with caution as it is meant as a discussion ;-)
    As I see it there is no logical way to extend the instance by adding a controlfile.
    The following procedure might work (has not been tested)
    I think you have to make a controlfilebackup with the database closed in normal mode using RMAN.
    Further you might be able to edit the pfile with create pfile from spfile and further create spfile from pfile. Extending the controlfile parameter to represent number and names of controlfile needed.
    With this done, the database is closed normal with a controlfile copy presented somewhere on the filesystem.
    startup mount;
    restore controlfile from '<backup controlfile location>'
    alter database mount;
    alter database open;
    Any thoughts about this procedure guys?
    Rgds
    Kjell Ove

  • File copy with 2 IDE Drive and Soundblaster problem

    Hi,
    When i try to copy large files my system will usually lock (windows totally freezes, the only solution is to do a hard reset). I cut the problem down to beeing an issue with my sound blaster live platinum 5.1.
    Everything is working fine when I remove the soundblaster.
    I read somewhere that this problem was known with former motherboard with VIA chipset like KT133 but I was hoping it had been fixed since then...
    Here's my config :
    KT6 Delta 2 FISR
    Athlon Barton 2500+
    512 Mo  RAM
    2 IDE Drive (not on the same IDE connector)
    Creative Live Sound Blaster Platinum 5.1 (CT4830)
    I have upgraded all the possible drivers : VIA4in1 (v4.51), latest BIOS upgrade (E6590v2.0), latest creative drivers....
    I tried a lot of different settings in the BIOS (PCI latency, PCI bus mastering etc...)
    This is really anoying...
    Please help !!!

    change pci latency to 96.
    change "system performance setting" within DRAM settings to "FAST"
    you could also;
    try changing "System Bios Cachable" to "Enabled"
    and change "C000 Shadow" to "Cacheable"
    im using all those above settings, and thats with ALOT of drives attached as well, and ive been copying 20+GB files all over the place including over network drives.

  • JProgressBar while file copy

    Hello,
    I give backup option in my application.
    so while taking backup (just file copy), i need to show the status of the file copying in JProgressbar
    Can any one give solution with sample.

    import java.awt.*;
    import javax.swing.*;
    public class X {
        public static void main(String[] args) {
            JFrame f = new JFrame("X");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JProgressBar bar = new JProgressBar(0,100);
            bar.setStringPainted(true);
            final Updater updater = new Updater(bar);
            f.getContentPane().add(bar, BorderLayout.NORTH);
            f.pack();
            f.show();
            Runnable example = new Runnable() {
                public void run() {
                    for(int i=0; i<=100; i+=5) {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                        updater.update(i);
            new Thread(example).start();
    class Updater  {
        private final JProgressBar jpb;
        private boolean queued;
        private int val;
        private Runnable runnable = new Runnable() {
            public void run() {//called from EDT:
                int _val;
                synchronized(Updater.this) {
                    queued = false;
                    _val = val;
                jpb.setValue(_val);
        public Updater(JProgressBar jpb) {
            this.jpb = jpb;
        public void update(int _val) {
            boolean go = false;
            synchronized(this) {
                val = _val;
                if (!queued) {
                    queued = true;
                    go = true;
            if (go)
                SwingUtilities.invokeLater(runnable);
    }1. I'm assuming you're backing up in a non-EDT thread, to avoid locking up your GUI.
    2. If 1 is true, you have to be careful to call Swing using methods like SwingUtilities.invokeLater. See:
    http://java.sun.com/docs/books/tutorial/uiswing/overview/threads.html
    3. My Updater class is the heart of this example. It is smart enough to update the progress bar's future value while this value is queued for the EDT.

  • JPEG/PSD issue--I open a jpeg and edit it (levels, crop) and then "save as" and the save as option shows there are now levels in the image and it wants to save it as a .psd file or a copy with layers.  What am I doing that has these settings appear?

    JPEG/PSD issue--I open a jpeg and edit it (levels, crop) and then "save as" and the save as option shows there are now levels in the image and it wants to save it as a .psd file or a copy with layers.  What am I doing that has these settings appear?

    16bit? Pixels extending beyond the canvas? (from a crop with delete unused pixels turn off).  Have you previously been saving PSD files?
    IME you sometimes have to tell Photoshop that the first save of a session is JPG, and it remembers from there on.  The way to 'tell' Photoshop that JPG, or PDF, or PNG etc are now your preferred format is to Ctrl (Cmd) click on that format in the Save As drop down list.  So long as the file does not have parameters that your chosen format does not support, then this should work for you.
    [EDIT]  Just noticed that you did include 'Crop' in the subject line.  Do you have 'Delete cropped pixels' checked?

  • Itunes is copying/converting 500gb of music from .wma to .m4a files that are on an external drive onto my laptop which doesnt have enough room. how do i reroute these newly converted files somewhere with enough space for them?

    itunes is copying/converting 500gb of music from .wma to .m4a files that are on an external drive onto my laptop which doesnt have enough room. how do i reroute these newly converted files somewhere with enough space for them?
    new to itunes, used windows media player before that and always ripped music directly to an external hardrive and accessed it through the player. now that i downloaded itunes it is taking from the external hardrive and copying a second file for each song onto my lap top hard drive which does not have the capacity for all my music. as itunes converts music files i want them saved back onto my external drive or another location i have space for rather than the lap top. how do i change the setting to move the itunes media folder to another location. assuming that hitting copy and past and dropping it in a random location will cause a few errors.

    When I have done this, all I did was network the two machines and copy the contents of the iTunes folder to the other machine, and that's it.
    My understanding (which may not be 100% correct) is that the one file that is absolutely necessary is iTunes Library, and that the XML file is actually a copy auto-generated from the iTunes Library, appearing in a different format only for non-iTunes apps that take advantage of the iTunes Library data.
    As far as I know, if you simply have the Library (database) file and all your original music files, iTunes on that computer should operate as it did on your old computer. I believe that the Album Artwork, Genius Data, and XML files can be regenerated from the Library file. Not sure about the Extras file.

  • I am batch processing in PS 2014 (watermark and saving as jpeg from ps file). I get the message for some but not all 'this file needs to be saved as a copy with this option'. And then I have to save it manually. Does anyone know why this happens? (It is j

    I am batch processing in PS 2014 (watermark and saving as jpeg from ps file). I get the message for some but not all 'this file needs to be saved as a copy with this option'. And then I have to save it manually. Does anyone know why this happens? (It is just a plain photoshop file, a watermark is added, then save as jpeg - the jpeg is saved to a different folder than the original photoshop file.)  It happens for about 10 of 30/40  files approximately . Thank you, Kathryn

    I believe I have figured it out - I need to flatten the image, even though there are no layers except for layer 0, first.

  • Problem with UTL FILE COPY

    Hi,
    I am facing one small problem in UTL FILE COPY package. We have an automated scheduled batch process. As a daily batch process it moves the files from one folder to other. During movement, it first copies the file from source folder to destination folder using FILE COPY package and then removes the file using FILE REMOVE package from the source folder.
    Few cases are found that the file when files are copied they are copied as 0 bytes in destination folder but the source file had 1 MB file size. The interesting part is I am unable to replicate the issue. Means when i try to run once again the package its working properly and files are copied with correct size. This kind is issue is occuring very rarely though as once in month but the question is why FILE_COPY package is not working properly sometimes.. I am unable to understand.
    Thanks a lot for going through this. Any suggestions.
    Regards,
    Ashish

    Anyhow make sure that the copy will start after the full generation of files.
    You can think like a spool file generation with huge data. In that case initially spool file available with 0 byte only. After finish of query only it shows its actual size.

  • How do I not copy hidden files associated with photos

    I want to put photos on my new digital picture frame. It can be plugged into a USB port and looks like a disk drive.
    I select and drag the photos I want to the device, but there is a hidden file for each one that gets copied as well. The device doesn't know what to do with those files. They don't cause a problem, but do take up space.
    How can I keep from copying those files?

    I'd like to be able to see the hidden files in the Finder so that I (hopefully) could select them and delete them before transferring the files to my digital photo frame.
    When you saw and deleted them using Terminal, were they present on your HD, or did you only look at the files already transferred to the USB photo frame device?
    The hidden "._" files are "resource fork" files, and when you make hidden files visible in Finder you might find that they exist only on the USB device, having been created there by the transfer process itself - see:
    *Apple Double Format Creates File Name With the Prefix '._'*
    http://support.apple.com/kb/TA20578?viewlocale=en_US
    Also take a look at [Blue Harvest|http://www.zeroonetwenty.com/blueharvest].
    They don't cause a problem, but do take up space.
    How much space? If not excessive, then leaving them alone would also be an option!

  • Looking for a file manager with copy queue

    Hey,
    I'm looking for a file manager with a file-copy-queue feature.
    It is useful when browsing mounted samba shares, and you find something you want to copy.
    You'll then start copying the files, and then spot another useful folder. You start copying that as well
    and suddenly you got 5 different file copies processing at the same time, which decreases the copy speed.
    I also miss the feature when transfering files from my external harddrives.
    If there is a lot of FM's with this feature, I prefer one without kde-dependencies, as I am using xfce.

    Ranguvar wrote:If MC really does have that as a feature, it's once again proved itself _the_ graphical (sorta) file manager.
    sorry for misinformed.
    mc has a background job option while copying, it is not exactly a queue like functionality, but simulating to be a queue, and you can stop/resume a background job.

  • Help with large file copy to WKS

    I need to copy a folder and all of it's contents from
    \apps\reallybigfolder to each workstation at c:\putithere.
    Because of the size of the file copy, I chose to create an app object
    with logic that says if xxx.exe exists then do not push. Basically, I
    don't want this thing to just run constantly. I need it to run one time
    to each workstation on the network when the users log in.
    I have tried pointing the app object to \public\ncopy.exe and then
    setting the parameters the way I want them, but I keep getting an
    error: "Cannot load VDM IPX/SPX Support". The two files in the folder
    are copied, but the subfolders are not. I have tried using the /s/e
    switches, but it does not help.
    I have also tried writing a .bat file, to test it - but I get the same
    results as above. So next I tried using copy instead of ncopy. I do not
    get the error message, but it still does not copy any of the subfolders.
    Is there another way? An easier way? I really appreciate the help.
    Tony

    What you are doing should work.
    It sounds as if there are some other workstation issues going on.
    I don't think I seen or could make the error "Cannot load VDM IPX/SPX
    Support" happen if I tried. Perhaps this would happen w/o a Novell
    Client installed. In such a case you could use XCOPY or ROBOCOPY.
    (Robocopy is way cooler than XPCOPY and is free from MS.)
    You can also use the "Distribution Tab" and the "Files" section to copy
    entire directories. Just use *.* as the source.
    [email protected] wrote:
    > I need to copy a folder and all of it's contents from
    > \apps\reallybigfolder to each workstation at c:\putithere.
    >
    > Because of the size of the file copy, I chose to create an app object
    > with logic that says if xxx.exe exists then do not push. Basically, I
    > don't want this thing to just run constantly. I need it to run one time
    > to each workstation on the network when the users log in.
    >
    > I have tried pointing the app object to \public\ncopy.exe and then
    > setting the parameters the way I want them, but I keep getting an
    > error: "Cannot load VDM IPX/SPX Support". The two files in the folder
    > are copied, but the subfolders are not. I have tried using the /s/e
    > switches, but it does not help.
    >
    > I have also tried writing a .bat file, to test it - but I get the same
    > results as above. So next I tried using copy instead of ncopy. I do not
    > get the error message, but it still does not copy any of the subfolders.
    >
    > Is there another way? An easier way? I really appreciate the help.
    >
    > Tony
    Craig Wilson
    Novell Product Support Forum Sysop
    Master CNE, MCSE 2003, CCN

  • Issues with Lion's Finder File Copying (+ Temporary Solution)

    1) When copying a file to my workplace's file server (via SMB), the file will appear to copy, and the file's "placeholder" will appear. Upon completion of the copy, the file will disappear.
    2) When copying multiple (presumably large) files to my external FireWire 800 drive, the file copy progress window will close, as though the copy has succeeded. However, upon closer inspection, the file sizes of the copied directories do not match, and many files are missing.
    In the meantime, it appears that the "ditto" command with the -rsrcFork flag will copy files correctly.
    If you aren't familiar with command line, but want to give this a whirl (if you are in a tight spot, for example), here's how to copy a text file called "myfile.txt" from your desktop to an external drive named "Storage":
    ditto -rsrcFork ~/Desktop/myfile.txt /Volumes/Storage

    isnt working for me.. getting this:
    ditto: can't get real path for source

  • JPG files copied to Philips Picopix 3410 are currupted with a prefix of ._ and will not display on the PicoPix

    JPG files copied to Philips Picopix 3410 are currupted with a prefix of ._ and will not display on the PicoPix. Help please?

    There are a couple of ways to remove these items from the drive.
    One is with the $15 shareware app, BlueHarvest. It will remove the AppleDouble files from the drives you want the ._ files removed from, and has an option to prevent them from being written to non Apple formatted drives in the first place.
    But the free and pretty easy way to do it is to use Terminal. From what I can see in the manual for your projector, you can only get images to it on either an SD card or a USB flash drive. So I'm going to assume a USB drive for the following.
    Plug in your MS-DOS formatted drive so it appears on the Mac desktop. Open Terminal and enter:
    dot_clean -m
    Enter a space after the -m . Then drag and drop the icon of your flash drive into the Terminal window. It will fill in the path of the drive. Press Enter. All ._ files will be removed from that volume.
    Actually, I think it removes all files that start with a period. None of which are of any great importance on a DOS formatted drive. Such as the hidden trash for that drive. The next time you plug the drive in, OS X will simply recreate it.

Maybe you are looking for

  • How can I get the music on my iphone onto my laptop?

    So, a while back, my father and I switched laptops. Since we did this, I have HIS itunes account on my laptop. He told me to uninstall itunes and reinstall it and then log into a new account that I've made. I did so, several times. Every time I open

  • Advice needed on suitability and hardware requirements...

    Hiya folks... I'm after a bit of advice...regarding whether or not Aperture will be suitable for me, considering my current Apple hardware and my current "workflow". I'm fairly new to digital SLR photography (hobbyist only)...but have had a variety o

  • How do you select the play length bar in an iphone/ipod?

    Sometimes I have a single song file of a book which is quite long, 10 hours, so I need to be able to restart where I left off. It is easy to mess up and end up back at the beginning. I have noticed that sometimes Imusic shows a play back length bar w

  • Oracle 9i R2 EE XP Professional Listener Problem

    One embarrased Oracle DBA. I've successfully installed Oracle on so many windows platforms that I've lost track. The specs: Dell Inspiron 5100 Windows XP Professional 2002 SP 1 2.66 GHz P4 CPU 512 MB RAM 1 GB Pagefile (swap) Macafee Virus Protection

  • TA24326 How do you repair Apple Software Update in Windows 7?

    When I open iTunes it says a new version (10.6.3) is available, and I click on "download" but nothing happens.  I then go to Apple Software Update and no updates are found.