File transfer to teh 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 ? using DataOutputStream or FileOutputStream ?
this is my 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);
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(allinone));
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");
oos.close();
// Thats the part which on client side,then i want to send the file to
// the server to do the following
DataInputStream dis = new DataInputStream(new FileInputStream(allinone));//the part i want to replace to get my file so i can process it
while(count!=0){
String fn=dis.readUTF();
System.out.println(fn);
String text=dis.readUTF();
System.out.println(text);
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();
}
}
View Answers
Related Tutorials/Questions & Answers:
File transfer to teh server - Java BeginnersFile transfer to
teh server hi,,
I've been trying to make... on client side,then i want to send the
file to
// the
server to do... and then the program read all the files and then save the content of all in 1
file Advertisements
File transfer from client to server - Java BeginnersFile transfer from client to server hi,,
I've been trying to make an application where the user select a
file using JFileChooser and then the program directly send it to the
server using client/
server sockets, I've tried
File transferFile transfer Hi there... I would like to know is it possible to
transfer files from one directory to another with out
file io operations
File TransferFile Transfer How to create a
file in
server side using java swing
scp using file transfer - Securityscp using
file transfer scp(secure copy protocol) using to download a
file from linux
server to windows xp .
using scp,
username, password authentication
What is FTP (File Transfer Protocol)?FTP stands for
File Transfer Protocol, which is basically a network protocol used to
transfer files from one computer or host to another within a network... like mobile devices.
FTP or
File transfer protocol can be used for exchange
jsp upload file to serverjsp upload
file to server How to create and upload
file to
server in JSP?
Find the given example that explains how to upload single and multiple
file on
server using JSP
Uploading File on ServerUploading
File on Server Hello,
Can someone explain or suggest example. How do i uploading files on the FTP
Server.
Thanks
uploading file to tomcat serveruploading
file to tomcat server please tell me how to upload a
file to the URL "http://192.168.12.7:8000/tomcat-docs/" ?
thanks
Uploading the file on Server.Uploading the
file on
Server
This example will explain you how to upload the
file on FTP
server. ftp_put() command allows to upload an existing
file on the
server. For uploading a
file onto the FTP
server, first you have to login
How to upload file on FTP ServerHow to upload
file on FTP Server In my application there is a requirement of uploading the
file on FTP
server. How to upload
file on FTP
Server... is good and can be used in Java applications.
Read FTP
File Upload in Java for more
Server calling of .exe file in the client Server calling of .exe
file in the client I have a requirement with java webapplication.
We are using jboss as appserver on Linux machine.
How can I call a .exe
file from client machine?
I want to run .exe from webpage like
image file upload to a web server computer. But when I use it on a
server it don't work. My
server uses Apache Tomcat 5
server. How can I upload a
file to the web
server?
Here...image
file upload to a web server Refer roseindia post http
war file deploy in tomcat server - WebSeviceswar
file deploy in tomcat server can anyone tell me how i can deploy war
file in
tomcat
server ???? to deploy ur war
file ...jus start ur tomcat
server then type http://localhost:8080 in ur address bar
file uploading - Java Server Faces Questionsfile uploading HI this is swathi.Thanku for answering previous questions.Previously u helped me in
file uploading but is not working the description of problem is below:
The
file uploading code is working in lan
need to open a file that is in server using jsp need to open a
file that is in
server using jsp im doing a web application where i can upload and download pdf files from server.in this i created... is just want to open a pdf in jsp.is it possible to open sever
file from jsp.Plz
reading a file on server side - JSP-Servletreading a
file on
server side Thank you sir for replying... & reading a word
file in JSP which is uploaded by client.
please help me...:
Display
file upload form to the user
UPLOAD THE
FILE
Choose the
file file uploading - Java Server Faces Questionsfile uploading Hi thi is swathi . Thanku for answreing previous questions .But its not working for
file uploading . U ask me to send the entire code... for lan but its not working for
server
pls tell me where is the problem
Expalin the Web Hosting Bandwidth/Space/Transfer for you to store
file on
server.
Data
transfer: It is the total sum of data which... and the data
transfer terms.
Explain me all these concepts.
Thanks
Hello,
Bandwidth: The monthly data
transfer allowed from/to on your
server on monthly
file uploading - Java Server Faces Questionsfile uploading
In the mozilla browser if we browse the
file it takes only the
file name not the complete path and
file not found exception... of the specified
file located on any machine
Jar file - Java Server Faces QuestionsJar file Hi All,
What is the Jar
file to run The Jsf Applications.When i am trying to run in the Eclipse its not running.
Thanks in Advance,
Puppy
Hi friend,
Jar
file to run The Jsf Applications
jsf