V
V
Volodar Znatsky2017-02-14 21:24:22
Java
Volodar Znatsky, 2017-02-14 21:24:22

What is the problem with downloading files with Java features?

It is necessary for the program to download files, links to which I specify in the console. Some files are downloaded, for the rest - errors.
Method source code:

try{
         text += '*';
         int beginIndex = text.lastIndexOf('/');
         int endIndex = text.lastIndexOf('*'); 
         if (beginIndex != -1 && endIndex != -1){
           filename = text.substring(beginIndex , endIndex);
           URL url = new URL(text);
             ReadableByteChannel rbc = Channels.newChannel(url.openStream());
             FileOutputStream fos = new FileOutputStream(filename);
             fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
             fos.close();
             rbc.close();
             textOut = "The file " + filename.replace("/", "") + " is downloaded";
         }
       }catch(Exception e){
         textOut = "Error: " + e;
       }

Download attempts:2cf609d1b03b431980223d860333390a.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Oparin, 2017-02-14
@ja8mraz

Well, they wrote to you - the file was not found.
And there is no such file (autoassa.ru/media/gallery/09890987.jpg*) on the site, you can be sure. The link has an extra asterisk at the end.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question