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();
                chooser.showOpenDialog(null);
                File file = chooser.getSelectedFile();
                String filename = file.getName();

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

Recommended Answers

All 6 Replies

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?

Yes of course...:)

What do you call copying a file from your PC to a server?

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:
http://www.java-forums.org/new-java/440-how-move-file-another-directory.html
and this as the third
http://download.oracle.com/javase/tutorial/essential/io/move.html
the second link uses the NIO (new I/O) classes from Java 7, and is better (if you have Java 7).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.