Viewed 3k times. I am doing the experiment for my own curiosity about transferring any file over the TCP connection between server and client My project is "Server receives a file" and "Client sends that file" But seems like something going wrong, The client-end can send the whole file and Server-end also can receive the whole file BUT after receiving at the server-end the file cannot be open it's like something went wrong while reading and sending its chunks Could you check if I'm doing something wrong Here's my code for Server side import java.
IOException; import java. ServerSocket; import java. BufferedOutputStream; import java. File; import java. FileOutputStream; import java. ObjectInputStream; import java. BufferedInputStream; import java. FileInputStream; import java. InputStream; import java. ObjectOutputStream; import java. Socket; import java. UnknownHostException; import java.
Jessada Dissopa Jessada Dissopa 77 2 2 silver badges 11 11 bronze badges. With Java or through window interface? SotiriosDelimanolis I think the OP means that the file was corrupted during the transfer — vandale. Escaping backslashes only applies to String literals. Add a comment. Active Oldest Votes. You shouldn't flush after every write, only at the end of the transfer. Sign up or log in Sign up using Google.
Sign up using Facebook. Sign up using Email and Password. Connect and share knowledge within a single location that is structured and easy to search. I am new to Java networking, and having looked for a resolution for my problem for a while now, I figured why not ask some advice from some more qualified people on this matter?
I currently have made a small tool which manages a server of mine, and another small client tool. My goal is for the tool to be able to send commands from the client to the server computer. This way I can perform certain actions on the server computer from another machine, including sending a zip archive with updated files. I have the basics setup: a TCP connection that sends a command from client to server server replies with a confirmation and then I would like the supposed action to take place.
My question now is this:. When sending a file. I would not only like to send the file to the server, but also when it arrived to extract and replace the existing files. EDIT: This is what I used for transferring a file from the client to server, however the file doesn't reach the destination in full size..
You did not get InputStream from the socket after serverSocket. Open InputStream on the socket. Refer to working example at : Write and Read File over Socket. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Java file transfer file to server Ask Question. Asked 6 years, 4 months ago. Active 5 years, 6 months ago. Viewed 25k times. My question now is this: When sending a file.
Kind regards, Alex EDIT: This is what I used for transferring a file from the client to server, however the file doesn't reach the destination in full size.. D: Server package server. BufferedInputStream; import java. File; import java. FileInputStream; import java. IOException; import java.
OutputStream; import java. ServerSocket; import java. BufferedOutputStream; import java.
0コメント