I want to browse & upload file to a folder.How can i do that in java.I can browse for a file.This is the code that i used....

JFileChooser chooser = new JFileChooser();
                File file = chooser.getSelectedFile();
                String filename = file.getName();

Plz tell me how to upload a file to a folder???

Edited by Ezzaral: Added code tags. By 45 posts, you should know to use them and you should also be aware not to use "chat speak".

6 Years
Discussion Span
Last Post by JamesCherrill

how to upload a file to a folder

I assume that the file is on your PC and the folder is on a server.
If that what you have,
then you need some code on the server that you can give the file to and tell it where you want the file saved (the folder).
FTP is one way that this is done.
It depends on what code is on the server that will do what you want done.


@ NormR1 : Actually I just want to upload a image to a folder in the PC.Not to a server.Becuase i want to move a image from its' source folder to my project folder.When i browse and give select the image,i should be able to upload it to my project folder.


I was confused when you said you wanted to upload a file.
Do you call moving/copying a file from one folder on a PC to another folder on the same PC: uploading?

Edited by NormR1: n/a


I guess you can call it whatever you like, although you would have a lot more success finding stuff if you used the same words as everyone else.
Anyway, Googling java move file gives this as the first hit:
and this as the third
the second link uses the NIO (new I/O) classes from Java 7, and is better (if you have Java 7).

Edited by JamesCherrill: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.