Search code examples
javaandroidr.java-file

Android: how can i find file path


i'm using a source code like this:

PrintWriter fout = new PrintWriter(new FileWriter("plot.txt"));
fout.println("#\tX\tY");

i want to find path of "plot.txt", any help? best regards.


Solution

  • If you use File instead of FileWriter you can easily call the getPath() or getAbsolutePath() method from File.

    I have looked in the api of PrintWriter and FileWriter and there are no methods to determine the path.

    http://developer.android.com/reference/java/io/PrintWriter.html

    http://developer.android.com/reference/java/io/FileWriter.html

    Example:

    File f = new File("test/.././file.txt");
    System.out.println(f.getPath());
    System.out.println(f.getAbsolutePath());