I'm working on a Java file downloader, so I just downloaded a video file with app and without app, so I saw file-size differences between that files. And I couldn't open the file which I downloaded by using my Java app. When I open them using Notepad++, I saw randomly generated symbols inside. What am I doing so wrong?
https://i.stack.imgur.com/LYDVm.png - here, as you can see randomly generated question marks there. https://i.stack.imgur.com/0rpSm.png - but in the original file, they doesn't exist. https://i.stack.imgur.com/5XC8q.png - here's the file sizes, I just placed "+" for the generated file.
Here's my code:
String currentRange = "bytes=0-"+num*13107200;
System.out.println(num + " is executing");
URL file = new URL(url);
FileOutputStream stream = new FileOutputStream("tmp"+num+".mp4");
HttpURLConnection urlConnection = (HttpURLConnection) file.openConnection();
urlConnection.setRequestProperty("Range", currentRange);
urlConnection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(
urlConnection.getInputStream()));
String inputLine;
final PrintStream printStream = new PrintStream(stream);
while ((inputLine = in.readLine()) != null)
printStream.println(inputLine);
in.close();
printStream.close();