Server
public static void activ(ServerSocket serverSocket) throws IOException { Socket socket = serverSocket.accept(); InputStream sin =socket.getInputStream(); OutputStream sout = socket.getOutputStream(); FileInputStream fin = new FileInputStream(new File("Log.txt")); InputStream sfin = new BufferedInputStream(fin); int res = IOUtils.copy(sfin, sout); fin.close(); sfin.close(); sout.flush(); fin = new FileInputStream(new File("Client.png")); sfin = new BufferedInputStream(fin); res = IOUtils.copy(sfin, sout); sout.flush(); sout.close(); socket.close(); Client
public class Main { public static void main(String[] args) throws IOException { Socket socket = new Socket("127.0.0.1", 15123); InputStream in = socket.getInputStream(); FileOutputStream fout = new FileOutputStream(new File("Log.txt")); OutputStream out = new BufferedOutputStream(fout); int res = IOUtils.copy(in,out); out.close(); out.flush(); fout = new FileOutputStream(new File("Client.png")); out = new BufferedOutputStream(fout); res = IOUtils.copy(in,out); out.flush(); out.close(); in.close(); //bos.flush(); //bos.close(); socket.close(); } }
I am trying to transfer files using IOUtils.copy (), but I have encountered such a problem that the program adds all the files to one file. I will give an example to make it a little clearer: I am trying to transfer 2 files "Log.txt" and "Client.png". Upon completion of the program, these 2 files become one, i.e. shuffled. Who knows how to solve this problem? The file "Log.txt" itself looks like this:
Update /images Client.png Small Update /images Close.png Small But at the exit he gives me the following:
Update /images Client.png Small Update /images Close.png Small<содержимое Client.png>