Results 1 to 11 of 11
- 01-30-2009, 11:45 AM #1
Member
- Join Date
- Jul 2008
- Posts
- 3
- Rep Power
- 0
- 01-30-2009, 12:02 PM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 286
- Rep Power
- 13
What exactly do you mean by placing a file, do you want to send a file from one machine to another?
- 01-30-2009, 12:04 PM #3
Member
- Join Date
- Jul 2008
- Posts
- 3
- Rep Power
- 0
yep
yep can u please send the sample code for it
- 01-30-2009, 12:20 PM #4
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 286
- Rep Power
- 13
Java Code://FileSender.java import java.net.*; import java.io.*; public class FileSender{ public static void main(String[] arg){ try{ FileInputStream fis=new FileInputStream("FileSender.java"); /*creating a socket to send data to 192.168.1.123 i.e. IP address of the machine where the file is to be sent and 1000 is the port number on which server listens requests*/ Socket socket=new Socket("192.168.1.123",1000); OutputStream os=socket.getOutputStream(); int ch=0; System.out.println("Sending file FileSender.java to 192.168.1.123"); while(true){ ch=fis.read(); if(ch==-1) break; os.write(ch); } fis.close(); os.close(); System.out.println("Sending process completed"); } catch(Exception e){ e.printStackTrace(); } } } //FileReceiver.java ------------------ import java.net.*; import java.io.*; public class FileReceiver{ public static void main(String[] arg){ try{ //we are creating the socket on port 1000 ServerSocket server=new ServerSocket(1000); System.out.println("Server running..."); Socket socket=server.accept(); InputStream is=socket.getInputStream(); FileOutputStream fos=new FileOutputStream("d:\\a1.txt"); int ch=0; System.out.println("Storing received contents to d:\\a1.txt"); while(true){ ch=is.read(); if(ch==-1) break; fos.write(ch); } is.close(); fos.close(); System.out.println("Receive process completed"); } catch(Exception e){ e.printStackTrace(); } } }
Compile both the codes , first execute FileReceiver then execute FileSender.
- 01-30-2009, 12:59 PM #5
teach the OPs...
dswastik... it's propobably not a good idea to send complete solutions to the OPs... there's no learning process envolved ... to easy for the OP to just cut & paste & forget. It better to provide snippets, pseudo code, hints, links, etc.
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 01-30-2009, 01:02 PM #6
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 286
- Rep Power
- 13
Sorry about that, will keep this in mind for future.
- 01-30-2009, 01:06 PM #7
Sure ... no problem... and thanks for understanding... the forum is here to help people with their Java programming problems and questions...
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 01-30-2009, 01:25 PM #8
Member
- Join Date
- Jul 2008
- Posts
- 3
- Rep Power
- 0
thanks dude :)
- 01-30-2009, 05:44 PM #9
Member
- Join Date
- Jan 2009
- Posts
- 92
- Rep Power
- 0
What if you do not know the name of the file before hand? for example i may want to fill in that file name with whatever a drop down menu provides...
- 01-31-2009, 06:49 AM #10
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 13
Use a JFileChooser for file selection.
- 02-28-2012, 08:44 PM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Similar Threads
-
excecuting a jar file by calling a java class
By Lavanya.vitria in forum Advanced JavaReplies: 1Last Post: 12-13-2008, 12:11 PM -
remote file access problem
By kib_tse in forum New To JavaReplies: 2Last Post: 08-14-2008, 06:04 PM -
How to read a .EML file present on Remote Desktop?
By anil@prokarma in forum New To JavaReplies: 0Last Post: 06-12-2008, 02:05 PM -
Applet and remote file
By Preethi in forum Java AppletsReplies: 0Last Post: 06-03-2008, 05:54 AM -
how to load a file in remote machine
By christina in forum New To JavaReplies: 1Last Post: 08-06-2007, 09:33 PM
Bookmarks