开发者

have ones app copy file from webpage

开发者 https://www.devze.com 2023-01-11 13:52 出处:网络
I have made an app that have to copy a file from a webpage, the following code doesn\'t do the job, it can\'t find the file

I have made an app that have to copy a file from a webpage, the following code doesn't do the job, it can't find the file

File ekstern = new File("http://192.168.13.40/cache.manifest");

copyFile(ekstern, intern);

and the copyFile method:

    public static void copyFile(File in, File out) throws IOException {
        FileChannel inChannel = new
            FileInputStream(in).getChannel();
        FileChannel outChannel = new
            FileOutputStream(out).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(),
                        outChannel);
        } 
        catch (IOException e) {
            throw e;
        }
        finally {
            if (inChannel != null开发者_运维百科) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
   }

But the code says that the file doesn't exists

testing with ekstern.exists()


You can't use File object to get something from a webpage. You have to use an HttpClient

0

精彩评论

暂无评论...
验证码 换一张
取 消