Go Back   Java Programming Forums > Java Standard Edition Programming Help > File I/O & Other I/O Streams


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: 35
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 Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 03-07-2008, 01:18 PM
JavaPF's Avatar
mmm.. coffee
 
7 Highscores

Join Date: May 2008
Location: United Kingdom
Posts: 1,581
Thanks: 103
Thanked 93 Times in 86 Posts
JavaPF is someone you want to know!JavaPF is someone you want to know!JavaPF is someone you want to know!

I'm feeling Stressed
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 syntax highlighted code tags around your code: [highlight=Java] code here [/highlight]

Forum Tip: Add to peoples reputation () by clicking the button on their useful posts.
Reply With Quote
  #3 (permalink)  
Old 04-07-2008, 04:37 AM
Member
 

Join Date: May 2008
Posts: 35
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: 25
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: 35
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: 25
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
mmm.. coffee
 
7 Highscores

Join Date: May 2008
Location: United Kingdom
Posts: 1,581
Thanks: 103
Thanked 93 Times in 86 Posts
JavaPF is someone you want to know!JavaPF is someone you want to know!JavaPF is someone you want to know!

I'm feeling Stressed
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 syntax highlighted code tags around your code: [highlight=Java] code here [/highlight]

Forum Tip: Add to peoples reputation () by clicking the button on their useful posts.
Reply With Quote
  #8 (permalink)  
Old 04-07-2008, 08:19 PM
Banned
 

Join Date: May 2008
Posts: 25
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: 35
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: 35
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/file-i-o-other-i-o-streams/70-folder-watching.html
Posted By For Type Date
Folder Watching This thread Refback 17-07-2008 06:43 AM


100 most searched terms
Search Cloud
2d arraylist java actionlistener actionlistener in java actionlistener java addactionlistener addactionlistener in java addactionlistener java applications of oops could not create java virtual machine xp double format java double to int double to int java double to integer in java double to integer java eclipse shortcut keys eclipse tutorial for beginners exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double java get mouse position java java 2d arraylist java actionlistener java addactionlistener java convert list to map java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming help java sendkeys java two dimensional arraylist java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics two dimensional arraylist java writing ipod apps

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