So, when you read byte stream from a file, you should not use char array.
You should use byte array.
http://howtodoinjava.com/2014/11/04/how-to-read-file-content-into-byte-array-in-java/
private static byte[] readContentIntoByteArray(File file)
{
FileInputStream fileInputStream = null;
byte[] bFile = new byte[(int) file.length()];
try
{
// convert file into array of bytes
fileInputStream = new FileInputStream(file);
fileInputStream.read(bFile);
fileInputStream.close();
} catch (Exception e)
{
e.printStackTrace();
}
return bFile;
}
'Java Programming' 카테고리의 다른 글
non-static nested class vs. static nested class (0) | 2016.09.18 |
---|---|
Static class in Java (0) | 2016.05.31 |
What does java.lang.Thread.interrupt() do? (0) | 2013.08.14 |
How to use Java String.split method to split a string by dot? (0) | 2012.08.06 |
socket example (0) | 2012.05.15 |