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 2 Years Ago by Orgest

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, ...

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

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.

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);


    }

}

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 article has been dead for over six months. Start a new discussion instead.