if (selectedFile != null) {
try {
FileInputStream fin = new FileInputStream(selectedFile);
byte[] data = new byte[previewLength];
int bytesRead = 0;
for (int i = 0; i < previewLength; i++) {
int b = fin.read();
if (b == -1) break;
bytesRead++;
data[i] = (byte) b;
}
preview = new String(data, 0, bytesRead);
fin.close();
}
catch (IOException e) {
// File preview is not an essential operation so
// we'll simply ignore the exception and return
}
}