Results 1 to 9 of 9
Thread: [SOLVED] Folder Watching
- 07-03-2008, 12:10 PM #1
[SOLVED] 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
- 07-03-2008, 01:55 PM #2
Have u started with itatleast getting .txt files from a directory?
Rest would be next step, Do it step by step and in a simple way.To finish sooner, take your own time....
Nivedithaaaa
- 07-03-2008, 02:18 PM #3
yeah i am able to List the content of a folder...but the main prob is to pick up the file from the folder...
suggest some ideas..
thanks for ur reply
-jazz
- 07-03-2008, 03:19 PM #4pick up the file
One way would be to copy the file from one directory to the other and then deleting the file from the one directory.
- 07-04-2008, 07:12 AM #5
Ur Right...it need to copy from the folder and send it to another path:cool:
If any new file comes into the Source folder it should be copied to the Dest Folder
- 07-04-2008, 11:15 AM #6
Is this what u wanted?
Java Code:public static void copy(File source, File dest) { try { BufferedReader br = new BufferedReader(new FileReader(source)); BufferedWriter bw = new BufferedWriter(new FileWriter(dest)); int read = 0; while((read = br.read()) != -1) { System.out.println((char)read); bw.write(read); } br.close(); bw.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
To finish sooner, take your own time....
Nivedithaaaa
- 07-04-2008, 11:17 AM #7To finish sooner, take your own time....
Nivedithaaaa
- 07-04-2008, 12:43 PM #8
Copy file into different folder and get the file created time
Here is the code
Java Code:import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class copyFiles { public static void copy(File source, File dest) { File cpDestFile = null; try { if (dest.isDirectory()) { if (source.isFile()) { System.out.println("File name = " + source.getName()); System.out.println("File name dest = " + dest.getPath()); System.out.println("File name cpDestFile = " + dest.getPath() + File.separator + source.getName()); cpDestFile = new File(dest.getPath() + File.separator + source.getName()); } else { System.out.println("Directory or File Not Found"); return; } } BufferedReader br = new BufferedReader(new FileReader(source)); BufferedWriter bw = new BufferedWriter(new FileWriter(cpDestFile)); int read = 0; while ((read = br.read()) != -1) { bw.write(read); } br.close(); bw.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String args[]) { copyFiles fcpy = new copyFiles(); File cpSrcFile = new File("D:\\Unprocessed_folder\\text1.txt"); File cpDestDir = new File("D:\\processingfolder"); fcpy.copy(cpSrcFile, cpDestDir); } }
Java Code:file = "C:\\yourFile.txt"; try { //NOTE FILES MUST NOT HAVE SPACES IN THE NAMES OTHERWISE THIS DONT WORK! Process ls_proc = Runtime.getRuntime().exec("cmd.exe /c dir " + getFilePath() + " /tc"); DataInputStream in = new DataInputStream(ls_proc.getInputStream()); for (int i = 0; i < 5; i++ ) { in.readLine(); } String stuff = in.readLine(); StringTokenizer st = new StringTokenizer(stuff); String dateC = st.nextToken(); String timeC = st.nextToken();//TIME CREATED in.close(); } catch (IOException e1) { System.out.println("Error in getting create time"); }
To finish sooner, take your own time....
Nivedithaaaa
- 07-04-2008, 01:49 PM #9
Similar Threads
-
folder cloning
By jad in forum Advanced JavaReplies: 1Last Post: 07-01-2008, 12:28 AM -
How can i copy a folder from one place to another..
By rajeshgubba in forum New To JavaReplies: 4Last Post: 06-14-2008, 02:21 AM -
add password to folder
By ismailsaleh in forum AWT / SwingReplies: 1Last Post: 01-08-2008, 05:46 AM -
how to use class in upper folder
By osval in forum New To JavaReplies: 1Last Post: 08-06-2007, 08:55 PM -
creation of new folder in the mail
By an8086 in forum Advanced JavaReplies: 1Last Post: 07-15-2007, 05:10 PM
Bookmarks