I am currently working on a homework assignment and I am completely trapped. I am on the last question and I can not understand how to go about completing the final work. Below is what I had to do:
-
The customer should save the file to the "Client" sub-directory of the Home Directory.
-
Check your program Make sure it works with binary files, not just text files, make sure that it works when both programs are on the same machine As well as when they are separated on the network.
When I want to use which port I start the client and asks how to use the IP and the port. The server immediately sends a list of files in the home directory "server" folder. I then respond to the client with the file number that I want to download. This is where I get stuck. I am not getting any information about doing this. Therefore, as you can see in your code below, I am trying to use FileInputReader to convert the file into an array of bytes. So I'm sending it to the customer I am then trying to get the received object of fileOutputReader in a file received bytes. But I can not seem to find the right way to do this, or even if I am doing the right way.
Client
int i = 0; While (I and LT; 1000) {string modified modified = infracer Readline (); System.out.println ("From the server:" + Modified Sense); I ++; } While (j & lt; 1000) {int byteString = inFromServer.read (); ArrayList & LT; Byte [] & gt; Bytes = new arrelisted & lieutenant; Byte [] & gt; (); Bytes.add (byteString); } Integer byteInt = new integer (byte string); FileOutputStream fo = New FileOutputStream (System.getProperty ("user.home") + "/client/text.txt"); Fo.write (byteInt.byteValue ()); }}
Server
byte [] bytes = new byte [1024]; FileInputStream fi = New FileInputStream (file.toString () + fileArray [userChoiceInt]); Fi.read (Byte, 0, 1024); OutToClient.write (Byte, 0, 1024); }}}
If someone can offer advice or offer the correct class or methods, I would appreciate it.
Thank you in advance.
There are some hints here without spoiling the whole thing
socket (server) And clients) can be easily accomplished. Using byte [] to transfer the file will ensure that your program will work with both ascii and binary files (files).
Another method is Remote Methment Invocation (RMI). I have not transferred the file using this approach, but I'm sure this is possible.
And if you do not know, after receiving the user's home directory, the following call is completed: System.getProperty ("User.home");
Comments
Post a Comment