Java File Name Clean cleanFilename(String filename)

Here you can find the source of cleanFilename(String filename)

Description

clean Filename

License

Open Source License

Declaration

public static String cleanFilename(String filename) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static final String VALID_FILENAME_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.@-";

    public static String cleanFilename(String filename) {
        byte[] fnBytes = filename.getBytes();
        byte c;//w w  w. ja  v a2  s .  co m

        for (int i = 0; i < fnBytes.length; i++) {
            c = fnBytes[i];

            if (VALID_FILENAME_CHARS.indexOf(c) == -1) {
                fnBytes[i] = '_';
            }
        }

        return new String(fnBytes);
    }
}

Related

  1. cleanFileName(final String originalFileName)
  2. cleanFileName(final String value)
  3. cleanFileName(String arg)
  4. cleanFileName(String badFileName)
  5. cleanFileName(String filename)
  6. cleanFilename(String filename)
  7. cleanFileName(String name)
  8. cleanFileName(String name)
  9. cleanFileName(String path)