Can I point to project files in this way?

1

Working with PHP, it is very easy to put a path scheme into a file, but in Java the schema might be different?

Can I point to a file starting, for example, by src File.separator ?

Example:

private static final String MODELS_PATH = "src" + File.separator + "models" + File.separator;

I can recover absolute path , but only if my way of pointing to a file above is correct.

Example:

File file = new File(".", MyClass.MODELS_PATH);

String absolutePath = file.getAbsolutePath();

Is the way to point to a file like MODELS_PATH correct?

    
asked by anonymous 28.12.2014 / 19:16

1 answer

1

I think this is what you want:

import java.util.*;
import java.lang.*;
import java.io.*;

class Ideone {
    public static void main (String[] args) {
        File path = new File("src", "models");
        System.out.println(path.getPath());
        System.out.println(path.getAbsolutePath());
        File novoPath = new File(".", path.getPath());
        System.out.println(novoPath.getAbsolutePath());
        System.out.println(novoPath.getPath());
    }
}

See working on ideone .

    
28.12.2014 / 20:01