Search code examples
javafileterminalfinder

Name of file with ? at the end


I have a series of files. When i see them, by terminal, i get this:

ls
filename1^J
filename2^J
filename3^J
filename4^J

But when i open them through Finder application i get this:

Finder
filename1
filename2
filename3
filename4

So, i make a simple Java program, based on the method below, to change their name e fix this situation:

String newPath = file.getAbsolutePath().replace("^J", "");

But it doesn't fix the problem. So, how can i rename those files?


Solution

  • I solved using this simple solution:

    filename = filename.replaceAll("[^a-zA-Z0-9.-]", "_");
    

    I hope this can be useful to others