I am downloading a text-file from example.com/test.txt and I need the contents only during the runtime of my app, they don't need to be saved to a static file.
My code so far:
InputStream input = new BufferedInputStream(getURL.openStream());
OutputStream output = new FileOutputStream(tempFile);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
How would I go about writing the online-file contents to a String rather than saving the file locally? I have tried appending data
to a String in the while-statement, but just get garbled text (as expected, but I don't know what else to do). Convert byte
back to String?
Thanks for your help!