0

When a large file is coming to server, it's taking few minutes to complete the download. During that period, I don't want to read the file content. I want to know the status of the downloading, i.e. whether downloading has completed or not. Only after successful completion of downloading, I want to read the file. I have written this method, but it's not working. Please help.

// checking downloading completed or not
private boolean saveFile(String fileName, URL download)
static String fileName = "Teleradiology Demonstration-20130909 1233-1.mp4";
File myFile=new File("E:/dicom_server_storage"); // reading directory

//  File myFile = new File("C:/Users/Subhojit/AppData/Roaming/Skype/My Skype Received Files");

URL download = myFile.toURI().toURL();
{
    try
    {  
// String saveTo = System.getProperty("user.dir") + "\\dicom_server_storage";
        String saveTo = "E:\\"; // save location

        ReadableByteChannel rbc = Channels.newChannel(download.openStream());

        FileOutputStream fos = new FileOutputStream(saveTo + fileName);

        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);

        fos.close();
        System.out.println("File download successfully completed.");
        return true;
    }
    catch (FileNotFoundException e)
    {
        e.printStackTrace();
    }
    catch (MalformedURLException e)
    {
        e.printStackTrace();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    return false;
    }
Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78
Subhojit Das
  • 131
  • 1
  • 8
  • If you are aware of the File-size, you can always compare the difference and convert that result into progress or how many percentage remaining. Multipart files have file-size as a parameter. – We are Borg Sep 09 '15 at 08:31
  • possible duplicate http://stackoverflow.com/questions/11239495/checking-if-file-is-completely-written – Anudeep Gade Sep 09 '15 at 09:26
  • another one http://stackoverflow.com/questions/10029365/how-to-test-if-a-file-is-complete-with-java – Anudeep Gade Sep 09 '15 at 09:27
  • It can be done through, java.nio.EventHander package. Trying to find the solution. – Subhojit Das Sep 09 '15 at 13:16

0 Answers0