在Java中下载大文件的状态

时间:2015-09-09 08:11:09

标签: java file download status

当一个大文件进入服务器时,需要几分钟才能完成下载。在此期间,我不想阅读文件内容。我想知道下载的状态,即下载是否已经完成。只有在成功完成下载后,我才能阅读该文件。我写过这个方法,但它不起作用。请帮忙。

// 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;
    }

0 个答案:

没有答案