Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners File transfer to teh server
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


raied
File transfer to teh server
0 Answer(s)      4 years and 11 months ago
Posted in : Java Beginners


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();
}
}


Advertisement
View Answers

Related Tutorials/Questions & Answers:
File transfer to teh server - Java Beginners
File 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
FTPClient : Server File transfer
In this tutorial, you will learn how to transfer file on the server by using FTPClient class
Advertisements
File transfer from client to server - Java Beginners
File 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 transfer
File 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 Transfer
File Transfer  How to create a file in server side using java swing
Secure file transfer protocol
Secure file transfer protocol  What is Secure file transfer protocol
scp using file transfer - Security
scp using file transfer  scp(secure copy protocol) using to download a file from linux server to windows xp . using scp, username, password authentication
How to transfer a file in java using SSH & Telnet
How to transfer a file in java using SSH & Telnet  How to transfer a file in java using SSH & Telnet
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
Remote file transfer in java using SSH & Telnet
Remote file transfer in java using SSH & Telnet  How to upload & download a file in java using SSH & Telnet
jsp upload file to server
jsp 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 Server
Uploading File on Server  Hello, Can someone explain or suggest example. How do i uploading files on the FTP Server. Thanks
uploading file to tomcat server
uploading file to tomcat server  please tell me how to upload a file to the URL "http://192.168.12.7:8000/tomcat-docs/" ? thanks
download mp3 file on server in iphone
download mp3 file on server in iphone  I want to download mp3 file on the server in iphone......plz help me give me the demo code
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 Server
How 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
FTP Server : Download file
This tutorial contains description of file downloading from the FTP server using java
Search file on Ftp Server
In this section, you will learn how to check existence of a file on the server by using java
FTP Server : Upload file
This tutorial contains description of file uploading to the FTP server using java
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
MySQL server PID file could not be found! [FAILED]
MySQL server PID file could not be found! [FAILED]  MySQL server PID file could not be found! [FAILED
Checking File existence on Ftp Server
In this section, you will learn how to check existence of a file on the server by using java
upload file to server and store recode in database
upload file to server and store recode in database  i want to upload a file into the server and store a recode in mysql database.any one know the code
Searching a word file on server in JSP - JSP-Servlet
Searching a word file on server in JSP  Seacrhing a word file on server side using JSP. I am Apache Tomcat Server. Please help me Sir
Create text file at client's directory from server.
Create text file at client's directory from server.  Need java code to create text file at client's directory from server..... Please Help
How to display transfer speed with rsync?
How to display transfer speed with rsync?  Hi, I am transferring the big file using rsync. I want to know how to display the transfer information such as transfer speed, total time, done precent ect. with the rsync command
war file deploy in tomcat server - WebSevices
war 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
Transfer Data to Sql Database
Transfer Data to Sql Database  Hey guys, how to Transfer data to SQl database using Java? Transfer data already stored in excel to Sql databse using Java? Looking for an easier method so i can comprehend
file uploading - Java Server Faces Questions
file 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
Delete a file from FTP Server
In this section you will learn how to delete file from FTP server using java
Advertisements
 

 

 

DMCA.com