|
||
|
|||
|
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
|
|
||||
|
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 |
|
|||
|
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.
|
|
|||
|
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 |
|
|||
|
Quote:
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. |
|
||||
|
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);
}
}
}
}
}
}
__________________
Don't forget to add code tags around your code: ![]() Has your problem been solved? Please mark your thread as solved |
|
|||
|
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 | |