Answer the question
In order to leave comments, you need to log in
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;
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question