How to read a TXT file when instantiating an object?

Asked

Viewed 11 times

0

At the moment of instantiating an object I need to go through parâmetro a directory with a file . txt and read the same. It would be something like this: Texto t1 = new Texto("c:\\pasta\\arquivo1.txt"); However, I don’t know how to do this construtor and at the same time read the file.

What I have in the main program:

public static void main(String[] args) {

    try {
        List<Texto> v = new ArrayList<Texto>();
        
        v.add(new Texto(args[0]));
        v.add(new Texto(args[1]));
        v.add(new Texto(args[2]));
        
        System.out.println(v);
    }
    catch ( ArrayIndexOutOfBoundsException e) {
        System.err.println("Informe tres arquivos para comparacao.");
    }
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.