Home Answers Viewqa Java-Beginners File transfer to teh server

 
 


raied
File transfer to teh server
0 Answer(s)      3 years and a month 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();
}
}

View Answers









Related Pages:
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
File Transfer
File Transfer  How to create a file in server side using java swing
FTPClient : Server File transfer
In this tutorial, you will learn how to transfer file on the server by using FTPClient class
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
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
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
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
Secure file transfer protocol
Secure file transfer protocol  What is Secure file transfer protocol
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
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
Image transfer using UDP - Java Beginners
making a project to transfer a file from one computer to another.The problem I am getting is that I can transfer only text files properly.The file transfer is using... objective is to transfer any file - text,word,ppt,pdf and especially image files(jpeg
How to transfer the excel content on consol to the database
How to transfer the excel content on consol to the database   Hi I have write the java code with which I am able to read the excel file and display its contents on the console but I am unable to transfer the content
Web Hosting Bandwidth/Space/Transfer
transported from the server to your computer. Data transfer is measured in bytes (B...Bandwidth and data transfer are vital terminology used in web hosting... refers to the rate of data transfer while data transfer indicate amount of data
ZF Transfer Control
How to transfer control from one page to another, in ZF: This is a very common activity in web site development that we need to transfer controls from one... that the command has created one action called redirect in the IndexController.php file
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
Web Server
or intranet for downloading the requested files using File Transfer Protocol, serving... Web Server Introduction       A web server is the combination of computer and the program installed on it. Web
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
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 : Upload file
This tutorial contains description of file uploading to the FTP server using java
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
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
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
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
upload files to apache ftp server - Ajax
()); // //Set our file transfer mode to either ASCII or Binary... the file that we will transfer and send... files to apache ftp server. I am using ajax framework for j2ee.Now I am okay
web server
web server  we need to restart tomcat server when we upload java class file but no need to restart when we upload jsp file. why
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
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-Servlet
reading 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 Questions
file 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
file uploading - Java Server Faces Questions
file 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
Jar file - Java Server Faces Questions
Jar 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
Data Transfer
Data Transfer       Swing supports data transfer through drag and drop, copy-paste, cut-paste etc. Data transfer works between Swing components within an application
java file handling
address which user enter. say if teh IP in teh file is IP=172.10.9.134...java file handling  Hi friends, My situation is i have file named "sample.conf" which contains more IP Adressess.Eg: the file contains "IP
Application Server
Application Server       An application server is an application program that accepts connections in order... on the same computer where the client application is running. Examples include file
servlet (tomcat server) and jar
servlet (tomcat server) and jar  how to create a jar file and where to place the jar file in tomecat server
how to measure data transfer speed
how to measure data transfer speed  how to measure data transfer speed?   Bits per second, is the commonly used unit for measuring the sped of data transmission
Server DB connection - JDBC
. One database is on my localhost and the other one is on server, I want to transfer the data from my localhost database to the database on the server. I have...Server DB connection  Hello Guys I want to connect two databases
How to upload zip file from android to server programmatically?????
How to upload zip file from android to server programmatically?????  hi , I want to upload zip file from android phone sdcard to server programmatically. So any one do this task in past so please share your experience with me
File download from server to client machine - JSP-Servlet
File download from server to client machine  hi, I want to save a pdf file to my client machine from a button provoded in a jsp page.The file... the generated report in server as follow. exporter.exportIntoPdfFile("c://reports

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.