Problems with directory accents

Asked

Viewed 80 times

0

I need to get the directory of a file that is inside the project, but the return is not respecting the accents of the folders.

Class that searches the directory:

package NewClass;

import java.io.File;

public class NewMain1 {

public static void main(String[] args) {
    File root = (new File(NewMain1.class.getResource("teste.txt").getFile())).getParentFile().getParentFile();
    System.out.println(root);
    File file1 = new File(root + "\\teste.txt");
    System.out.println(file1);
}    
}

The path is: "C: Users Desktop Administrator Pedro Javaapplication1 build classes".

But the output comes: "C: Users Desktop Administrator Pedro Aplica%C3%A7%C3%b5es Javaapplication1 build classes".

inserir a descrição da imagem aqui

  • 2

    See help: https://stackoverflow.com/questions/31649879/how-to-get-absolute-path-with-proper-character-encoding-in-java

  • Yes, that’s right, thank you

No answers

Browser other questions tagged

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