0

Hello

I have write some code to read a specific word from a text file. The file is located in a specific folder.
In the folder there are multiple files, i want to read first the file that is upload first in the directory.
After I have read file, I want to move it in another directory.
How i can do it ?

This the code that I have write.

package project1;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;


public class reuter22 {

    public static void main(String[] args) {
        String line = "";
        int lineNo;


        try {
                FileReader fr = new FileReader("C://Users/BJ001526/Desktop/folder/Ticket.txt");
                BufferedReader br = new BufferedReader(fr);
                for (lineNo = 1; lineNo < 24; lineNo++) {

                        if (lineNo == 23) {

                            line=br.readLine();

                        } else
                                br.readLine();
                }
        } catch (IOException e) {
                e.printStackTrace();
        }

        System.out.println(line.substring(33, 43) );

}

}

Edited by Orgest

3
Contributors
5
Replies
26
Views
2 Years
Discussion Span
Last Post by stultuske
0

ehm ... create a new file, copy the contents, then, delete the original one.
I don't get what it is you are asking. how to create the copy, or how to list all the files in a folder, or, ...

0

I need to read the oldest file in the directory.
After we read it, we want to move it in another directory.

0

if you check this link, you'll be able to check the creation date of the files.
then, it's a matter of comparing the files, based on that creationDate.

once, you determined which was created first, you have the oldest, and know which file to move to a new location.

-1
package arrayexample1;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class ReadText {
    public static void main(String[]args) throws FileNotFoundException, IOException
    {  FileOutputStream fos=new FileOutputStream("D://Malli");
        FileInputStream fis=new FileInputStream("c://users//desktop/malli/mallika.txt");
        int i;
        while((i=fis.read())!=-1)

           fos.write((char)i);


    }

}
0

malli:

the point of this forum is not to hand out custom made code, but to make suggestions, which can point the op to a sollution.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.