I'm having troubles with files in Java.
The issue is: I'm trying to copy a file (not only text, any kind) from one side of a socket to another. I read the file with a BufferedReader (byte by byte) and write them on a file with a FileOutputStream.
It works fine, but when I open the file it is not the same as te original, it is writing the bytes on a text file or something like that.
A piece of code:
in = new BufferedInputStream(s.getInputStream());
byte b[] = new byte[MAX_LENGTH];
File f = new File(name);
FileOutputStream fos = new FileOutputStream(name);
for(int i = 0; i < segments; i++){
in.read(b,i*MAX_LENGTH,MAX_LENGTH);
fos.write(b);
}
Where s is a opened socket (working fine), name the name of the file and segments the number of segments sent through the socket (segments of MAX_LENGTH).