Results 1 to 1 of 1
- 05-05-2010, 03:59 PM #1
Member
- Join Date
- May 2010
- Posts
- 1
- Rep Power
- 0
File transfer from Client to server
hi,,
I've been trying to make an application where the user select several fiels using JFileChooser and then the program read all the files and then save the content of all in 1 file and then send it to the server using client/server sockets, I've tried many ways and non seems to working .So whats the proper way to do it ?
Java Code:public class Main { static File[] f; public static void main(String[] args) throws Exception { JFileChooser jf = new JFileChooser("C:"); jf.setMultiSelectionEnabled(true); jf.showOpenDialog(null); int count=0; f = jf.getSelectedFiles(); File allinone = new File("All.dat"); JFileChooser jf2 = new JFileChooser(allinone); int returnVal = jf2.showSaveDialog(null); DataOutputStream dos = new DataOutputStream(new FileOutputStream(allinone)); FileInputStream fis=null; for (int i = 0; i < f.length; i++) { fis = new FileInputStream(f[i]); int fileSize = (int) f[i].length(); byte[] b = new byte[fileSize]; fis.read(b); String text=new String(b); String filename = f[i].getName(); System.out.println("FIle name " + filename + " size = " + fileSize); dos.writeUTF(filename); dos.writeUTF(text); dos.flush(); fis.close(); count= count+2; } dos.writeUTF("TheEnd"); dos.close(); // Thats the part which on client side,then i want to send the file allinone.dat to the server to do the following DataInputStream dis = new DataInputStream(new FileInputStream(allinone)); //the part where i want to replace allinone with the incoming file from the client socket while(count!=0){ String fn=dis.readUTF(); System.out.println(fn); // test String text=dis.readUTF(); System.out.println(text); // test count=count-2; byte[] textB=text.getBytes(); File f=new File("new"+fn); FileOutputStream ff=new FileOutputStream(f); DataOutputStream dd=new DataOutputStream(ff); dd.write(textB); } dis.close(); } }
Similar Threads
-
To transfer a file from client to server
By phani in forum NetworkingReplies: 4Last Post: 10-12-2010, 06:15 PM -
send file via client - server model
By spasavvas in forum NetworkingReplies: 15Last Post: 08-13-2010, 11:45 AM -
Sending a File from Server to Client and saving the file to Clients computer
By al_Marshy_1981 in forum NetworkingReplies: 8Last Post: 02-18-2010, 12:54 PM -
how to send mp3 file from server to client
By Jigga008 in forum NetworkingReplies: 0Last Post: 12-01-2009, 12:02 PM -
how to send a file from server to client and client saves the file?
By KoolCancer in forum New To JavaReplies: 3Last Post: 07-29-2009, 04:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks