Register FAQ Calendar Search Today's Posts Mark Forums Read

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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-07-2008, 09:43 AM
Member
 
Join Date: May 2008
Posts: 42
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
Java Programmer
 
Join Date: May 2008
Location: Deep inside the Eclipse IDE
Posts: 172
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...
Reply With Quote
  #3 (permalink)  
Old 04-07-2008, 04:37 AM
Member
 
Join Date: May 2008
Posts: 42
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
Member
 
Join Date: May 2008
Posts: 58
Engineeringserver.com 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
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
Member
 
Join Date: May 2008
Posts: 58
Engineeringserver.com 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
Java Programmer
 
Join Date: May 2008
Location: Deep inside the Eclipse IDE
Posts: 172
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.
Reply With Quote
  #8 (permalink)  
Old 04-07-2008, 08:19 PM
Member
 
Join Date: May 2008
Posts: 58
Engineeringserver.com 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
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
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


Custom Search
100 most searched terms
Search Cloud
"bad endpoint type" com.sun.xml.internal.messaging.saaj.soapexceptionimpl com.sun.xml.internal.messaging.saaj.soapexceptionimpl: bad endpoint type com.sun.xml.internal.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception com.sun.xml.internal.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: message send failed com.sun.xml.internal.messaging.saaj.soapexceptionimpl: message send failed com.sun.xml.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception com.sun.xml.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception: com.sun.xml.messaging.saaj.soapexceptionimpl: message send failed convert arraylist to map date_format_now eclipse shortcut keys ejb3 quartz java convert double to binary java forum java forums java jtextarea bold java jtextarea color java jtextarea font java jtextarea font size java programmer forum java programmers forum java programming forum java programming forums java read last line java read last line of file java sendkeys java.security.privilegedactionexception java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: bad response 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 javapf javaprogrammingforums jtextarea bold jtextarea font jtextarea font color jtextarea font size programing forums programming forums reset jcombobox saaj0008 saaj0008: bad response; bad request saaj0008: bad response; not found severe: saaj0008 severe: saaj0008: bad response; bad request severe: saaj0008: bad response; not found soap java.security.privilegedactionexception soapexceptionimpl: bad endpoint type textpad java

All times are GMT. The time now is 12:41 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.