I am trying to read the string that I get inside an outputStream that in turn is written there by a ftp - from a ftp server.
I'm stuck at this problem for about 2 hours and I find it hard to belive that it's so difficult to solve.
Is there any nice solution for my problem?
Here's the relevant code:
boolean success = false;
OutputStream outputStream = null;
try {
outputStream = new BufferedOutputStream(new FileOutputStream(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + fileName));
success = ftp.retrieveFile("/ViatorAndroid/" + fileName, outputStream);
} catch (Exception e) {
Log.d("FTPDownloadLatestVersion", "e = " + e.getMessage() + " " + Arrays.toString(e.getStackTrace()));
}
outputStream.close();
if (success) {
String versionNumberString = outputStream.getString(); // ??? I need here a way to get the string inside this output stream. Any clue how???
int versionNumber = Integer.parseInt(versionNumberString);
Log.d("FTPGetLastestVersionCode", "VersionNumber = " + versionNumber);
return BuildConfig.VERSION_CODE < versionNumber;
}
FileOutputStreamdoesn't remember what you wrote to it. It simply writes it to a file and then forgets about it. You can construct aByteArrayOutputStreamwhere the "some place" is a byte array, but pretty much everything else is just a pointer to some other place.