[Advanced-java] Auto selection of file from folder during upl
oading??
Lorin Davis
ldavis at pangaeainc.com
Fri May 9 21:23:57 2003
Oha yah you'd need a
uploadThread.start() called at in the UploadButtonClickACtion method
void UploadButtonClickAction (MouseEvent e) {
Thread uploadThread = new Thread () {
public void run () {
while (1) {
checkForFilesToUpload (UPLOAD_FOLDER) {
// sleep for 30 seconds before checking again -- not needed but would
// stop this loop from trashing your CPU
this.sleep (30000)
}
}
}
// ADd this line
uploadThread.start()
}
Also You would probbably want to disable the button after its been clicked
the first time or else everytime the clicked the upload button you would
start another thread searching for files to upload....
\-----Original Message-----
From: Lorin Davis [mailto:ldavis@pangaeainc.com]
Sent: Friday, May 09, 2003 11:05 AM
To: 'Bikash Paul'; advanced-java@lists.xcf.berkeley.edu
Subject: RE: [Advanced-java] Auto selection of file from folder during
upl oading??
What I would do is
When the Upload button is clicked Start a loop in a separate thread from
your main application that just checks the for the new files in the folder
and uploads them if they are there. Seeing as you move the files out of the
folder after they are uploaded, all you have to do check for more files in
the following loops. What you may want to do so your not always looping and
taking up CPU is put this on a timer or put a delay at the end of the loop
so maybe you would only check every 30 seconds or so..
Here's some sample code that might help you
void UploadButtonClickAction (MouseEvent e) {
Thread uploadThread = new Thread () {
public void run () {
while (1) {
checkForFilesToUpload (UPLOAD_FOLDER) {
// sleep for 30 seconds before checking again -- not needed but would
// stop this loop from trashing your CPU
this.sleep (30000)
}
}
}
}
void checkForFilesToUpload (String uploadFolder) {
File directory = new File (uploadFolder);
File[] files = directory.listFiles();
if (files.length > 0) {
uploadFiles (files)
}
}
void uploadFiles (File[] files) {
// do the code to upload you files here
}
hope this helps...
-----Original Message-----
From: Bikash Paul [mailto:bikashpaul_2001@yahoo.com]
Sent: Friday, May 09, 2003 6:56 AM
To: advanced-java@lists.xcf.berkeley.edu
Subject: [Advanced-java] Auto selection of file from folder during
uploading??
Hi all friends,
Iam facing with one problem I am developing one
uploading software for that i have used swing and
servlet.Now my problem is i want to give auto
selection of file from one folder means user just copy
the files from any computer on network and paste it in
predefind folder.And when they click on upload button
it should start uploading of file one by one and after
completion of uploading it move that file into another
folder one by one.Now my software doing it perfectly
but if user copy and paste any file in that predifined
folder from network computer during uploading then
they have to click upload button again after
completion of first queue of files(for example if user
first copy 10 files and start uploading and inbetween
uploading of that 10 files if user copy another 10
files from network computer then they have to click on
upload button again after completion of uploading of
first 10 files).But my user requirement is they want
to click on upload button once only at the time of
starting my application and my application
automatically select the file one by one from folder
and send it to destination.Means if they copy the file
from network machine inbetween uploading or any other
user from network send file in that folder then my
application should select those file automatically and
start uploading means they don't want to click on
upload button again.Can any one plz guide how I can
slove this problem.Below r my codes:-
Upload.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
suspendflag=true;
Resume.setEnabled(false);
Suspend.setEnabled(false);
dest=frame.m_txtURL.getText();
File ff=new File("d:\\DTMS\\Upload");
File[] files = ff.listFiles();
fileList = new Vector();
if(files == null)
{
textArea.append("There is no file");
return;
}
else
{
for (int j = 0 ; j< files.length ; j++)
{
fileList.add(files[j]);
}
}
java.util.Collections.sort(fileList, new
FileComp());//sorting by size
new Thread(new Runnable() {
public void run(){
for (int k = 0; k < fileList.size(); k++)//loop for
queue {
File fname = (File)fileList.get(k);
String str=fname.getName();
log("Destination:" +" "+ dest);
log("Uploading Progress\nPlease Wait....");
result=doPost(fname,dest);//method for read file &
send to servlet
String str2="Transfer apparently failed.";
String str3=result;
if(str2.equals(str3)){
Error(result);
}
else if(suspendflag==true){
File newfile =new File("d:\\DTMS\\Archives\\"+str);
fname.renameTo(newfile);
log("File" +" "+ str+" "+"Upload Completed !");
}
else if(suspendflag==false){
Error("** Transfer Suspended**");
}
}
}
}).start();
}catch(Exception exp)
{
Error("Error : " + exp.toString());
}
}
});
Regards
Bikash
__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com
_______________________________________________
Advanced-java mailing list
Advanced-java@lists.xcf.berkeley.edu
http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java
_______________________________________________
Advanced-java mailing list
Advanced-java@lists.xcf.berkeley.edu
http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java