I have a program which will download files from a specific URL and save them inside the default directory where .java files are stored. However, I want to set a specific location to store the downloaded files.
String locID = "C:\Users\user\Desktop";
This is the directory location I want to insert in the code below. Where in the code should I insert the path locID
?
RandomAccessFile file = new RandomAccessFile(getFileName(url), "rw");
file.seek(downloaded);
InputStream stream = connection.getInputStream();
while (status == DOWNLOADING) {
byte buffer[];
if (size - downloaded > MAX_BUFFER_SIZE) {
buffer = new byte[MAX_BUFFER_SIZE];
} else {
buffer = new byte[size - downloaded];
}
int read = stream.read(buffer);
if (read == -1)
break;
file.write(buffer, 0, read);
downloaded = downloaded + read;