This should be obvious, but I can't figure it out. I spent almost the whole day on this. I would love to buy a beer for someone who can make it easier for me.
File file = new File(filePath); byte[] bytes = new byte[(int)file.length()]; DataInputStream dataInputStream = new DataInputStream(new BufferedInputStream(new FileInputStream(filePath))); dataInputStream.readFully(bytes); dataInputStream.close(); return new String(bytes);
This is my code. I see that the size of the byte array is not suitable, but I can not determine the desired size. In addition, the content is also not incorrect. Only text characters seem to be in order.
It looks like the data from the binary is a real pain, I am really depressed.
One more thing: the content of the file is not text, it can be like a picture, video or PDF.
source share