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



Home Answers Viewqa Java-Beginners File transfer to teh server

Have Programming Question? Ask it here!
 
 
 


raied
File transfer to teh server
0 Answer(s)      4 years and 3 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 : 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
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
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
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  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
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
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
how to export the query result in SQL Server to .csv file?
how to export the query result in SQL Server to .csv file?  how to write table data into CSV file using SQL SERVER 2008
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
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
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
Starting MySQL.The server quit without updating PID file
Starting MySQL.The server quit without updating PID file  Starting MySQL.The server quit without updating PID file (/var/lib/mysql/xxxxxx.pid
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
Starting MySQL....The server quit without updating PID file
Starting MySQL....The server quit without updating PID file  Hi, My MySQL server is running on Centos and it is not restarting and giving following error: Starting MySQL....The server quit without updating PID file (/var/lib
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
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
How can store image in server folder when deployed with a .war file?
How can store image in server folder when deployed with a .war file?  Hi all; When I am using application.getRealPath() , it return null when deployed with a .war file and when I use hard code it shows syntax error or path
how to edit xml file which is currently running in web server - XML
server apache tomcat.I can add and modify xml file by giving Path like that "E... to give file location like that. I want to give file location from web server like...how to edit xml file which is currently running in web server  Hello
display multiple image file or pdf file in multiple column of a row from server or database
display multiple image file or pdf file in multiple column of a row from server or database  hello sir I have uploaded the file to the server and I want to display that file to the user page but I want to display that file
Problem to print from my properties file - Java Server Faces Questions
of this site. It is very interesting. So this is my problem: I have a jsp file where i try to print some messages from my properties file but when i execute it with JBOSS application server, by my navigator it shows MISSING:titreAchat
Upload file on server automatically on specific time - JSP-Servlet
Upload file on server automatically on specific time  Hi all, Is there any way to upload file on server on specific time automatically using java... only to upload a file? If java application running, which will be the best
Upload and insert the file contents - Java Server Faces Questions
Upload and insert the file contents  I want to browse and upload 2 files on server and insert the values into table from JSP page. So i have... be stored on server temporarily and then should be inserted into respective tables
 

 

 

DMCA.com