Go Back   Java Programming Forums > Java Programming > New to Java

Reply
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 03-07-2008, 09:43 AM
Member
 

Join Date: May 2008
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
jazz2k8 is on a distinguished road
Default Folder Watching

Hi Folks,

I am having some files(.txt) in a directory called as Unprocessed folder,i would like to take one by one file and send it to the processing path say it as..C:\processingfolder
Each time when an UnprocessFolder get any new file it should be sent to the processing folder.

Any Idea....thanks in advance


-jazz



Reply With Quote
  #2 (permalink)  
Old 03-07-2008, 01:18 PM
JavaPF's Avatar
Forum Admin
 
3 Highscores

Join Date: May 2008
Location: UK
Posts: 880
Thanks: 15
Thanked 39 Times in 39 Posts
JavaPF will become famous soon enoughJavaPF will become famous soon enough
Default Re: Folder Watching

Hey,

Do you want to do this with a Java application?

I think there is a way to do this with Windows...
__________________
Don't forget to add code tags around your code:

Has your problem been solved? Please mark your thread as solved
Reply With Quote
  #3 (permalink)  
Old 04-07-2008, 04:37 AM
Member
 

Join Date: May 2008
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
jazz2k8 is on a distinguished road
Default Re: Folder Watching

Yeah...with Java Only...Rep me ASAP

Thanks
Reply With Quote
  #4 (permalink)  
Old 04-07-2008, 07:01 AM
Banned
 

Join Date: May 2008
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Engineeringserver is on a distinguished road
Default Re: Folder Watching

use a thread that checks for a file every 1 sec (or less) , use a file inputstream /outputstream to read/write the file and a bufferedreader/scanner etc to process the file. Shouldn't be too hard to do it depending on the "processing" requiremens it can be done in a few hours.
Reply With Quote
  #5 (permalink)  
Old 04-07-2008, 09:17 AM
Member
 

Join Date: May 2008
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
jazz2k8 is on a distinguished road
Default Re: Folder Watching

ok thanks for ur reply...

i can list the files but not able to load them...means i can list the files from the Folder but not able to Move them...is any new file comes no it is not able to recognize...how to do this..please rep me..

thanks
Reply With Quote
  #6 (permalink)  
Old 04-07-2008, 10:50 AM
Banned
 

Join Date: May 2008
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Engineeringserver is on a distinguished road
Default Re: Folder Watching

Quote:
Originally Posted by jazz2k8 View Post
ok thanks for ur reply...

i can list the files but not able to load them...means i can list the files from the Folder but not able to Move them...is any new file comes no it is not able to recognize...how to do this..please rep me..

thanks
see my reply above, you can use this class i wrote to copy files from one directory to another: Engineeringserver.com | Copy a txt file from one location to another with Java

to process it automatcally you can use a thread that checks the unprocessed folder every second and call the method in my class to process the file or move the file to another directory.
Reply With Quote
  #7 (permalink)  
Old 04-07-2008, 04:35 PM
JavaPF's Avatar
Forum Admin
 
3 Highscores

Join Date: May 2008
Location: UK
Posts: 880
Thanks: 15
Thanked 39 Times in 39 Posts
JavaPF will become famous soon enoughJavaPF will become famous soon enough
Default Re: Folder Watching

Hey Jazz,

Here is a crude example for you. You will have to edit the code to check dir1 every minute or put it into a loop or something.

Currently this will take the text files from dir1 and re-create them into dir2.

You will also need to add code to delete the files from dir1 after creation.

Java Code
import java.io.File;
import java.io.*;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
 
public class ListFiles 
{ 
 public static String path1;
 public static String path2;
 public static String files;
 public static String fileName;
 
 public static void main(String[] args) throws Exception
{
   path1 = "/dir1/"; 
   path2 = "/dir2/";
 
  File folder = new File(path1);
  File[] listOfFiles = folder.listFiles(); 
  for (int i = 0; i < listOfFiles.length; i++) 
  {
 
   if (listOfFiles[i].isFile()) 
   {
   files = listOfFiles[i].getName();
       if (files.endsWith(".txt") || files.endsWith(".TXT"))
       {
 
          System.out.println(files);
 
          try
          {
          FileInputStream in = new FileInputStream(path1 + files);
          BufferedReader br = new BufferedReader(new InputStreamReader(in));
          String strLine;
 
     Writer output;
     File file1 = new File(path2 + files);
     String newline = System.getProperty("line.separator"); 
     output = new BufferedWriter(new FileWriter(file1));
 
          while((strLine = br.readLine())!= null)
          {
           //Write contents of text file
           output.write(strLine);
           output.write(newline);
          //System.out.println(strLine);
          }
 
           output.close();
 
          }catch(Exception e){
           System.out.println(e);
          }
 
        }
       }
  }
}
}
Let me know if you get stuck and ill try to finish this off. I'm away from the computer now though so thought id post this quickly.
__________________
Don't forget to add code tags around your code:

Has your problem been solved? Please mark your thread as solved
Reply With Quote
  #8 (permalink)  
Old 04-07-2008, 08:19 PM
Banned
 

Join Date: May 2008
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Engineeringserver is on a distinguished road
Default Re: Folder Watching

Quote:
Originally Posted by JavaPF View Post
Hey Jazz,

Here is a crude example for you. You will have to edit the code to check dir1 every minute or put it into a loop or something.

Currently this will take the text files from dir1 and re-create them into dir2.

You will also need to add code to delete the files from dir1 after creation.

Java Code
import java.io.File;
import java.io.*;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
 
public class ListFiles 
{ 
 public static String path1;
 public static String path2;
 public static String files;
 public static String fileName;
 
 public static void main(String[] args) throws Exception
{
   path1 = "/dir1/"; 
   path2 = "/dir2/";
 
  File folder = new File(path1);
  File[] listOfFiles = folder.listFiles(); 
  for (int i = 0; i < listOfFiles.length; i++) 
  {
 
   if (listOfFiles[i].isFile()) 
   {
   files = listOfFiles[i].getName();
       if (files.endsWith(".txt") || files.endsWith(".TXT"))
       {
 
          System.out.println(files);
 
          try
          {
          FileInputStream in = new FileInputStream(path1 + files);
          BufferedReader br = new BufferedReader(new InputStreamReader(in));
          String strLine;
 
     Writer output;
     File file1 = new File(path2 + files);
     String newline = System.getProperty("line.separator"); 
     output = new BufferedWriter(new FileWriter(file1));
 
          while((strLine = br.readLine())!= null)
          {
           //Write contents of text file
           output.write(strLine);
           output.write(newline);
          //System.out.println(strLine);
          }
 
           output.close();
 
          }catch(Exception e){
           System.out.println(e);
          }
 
        }
       }
  }
}
}
Let me know if you get stuck and ill try to finish this off. I'm away from the computer now though so thought id post this quickly.
Looks good, add a thread so that it checks for a new file and process it. Not that hard to code
Reply With Quote
  #9 (permalink)  
Old 07-07-2008, 04:48 AM
Member
 

Join Date: May 2008
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
jazz2k8 is on a distinguished road
Default Re: Folder Watching

Thanks alot....will let you know after completing this
Reply With Quote
  #10 (permalink)  
Old 08-07-2008, 09:23 AM
Member
 

Join Date: May 2008
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
jazz2k8 is on a distinguished road
Default Re: Folder Watching

Can we try with images....i.e. i need to upload .tif image.....:-)
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


LinkBacks (?)
LinkBack to this Thread: http://www.javaprogrammingforums.com/new-java/70-folder-watching.html
Posted By For Type Date
Folder Watching This thread Refback 17-07-2008 06:43 AM


  Google Custom Search
   

100 most searched terms
Search Cloud
actionlistener java addactionlistener arraylist to map convert double to int java convert double to integer java convert list to hashmap double to int java double to integer java eclipse shortcut keys ipod touch java java actionlistener java addactionlistener java convert double to int java convert list to map java double format java double to int java double to integer java format double java forum java forums java get mouse position java print time java programming forum java programming forums java read last line java read last line of file java sendkey java sendkeys java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: message send failed java.security.privilegedactionexception: com.sun.xml.messaging.saaj.soapexceptionimpl: message send failed javaprogrammingforums javaprogrammingforums.com jbutton addactionlistener jtextarea bold jtextarea bold text jtextarea color jtextarea font jtextarea font color jtextarea font size jtextfield font size programming forums quartz ejb3 scwcd books writing applications for ipod touch writing apps for ipod touch writing ipod applications writing ipod apps writing ipod touch apps writing itouch apps www.javaprogrammingforums.com

All times are GMT. The time now is 08:30 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.