Android Path Separator Get fixFileSeparators(File file)

Here you can find the source of fixFileSeparators(File file)

Description

Fix up file separators for platform independence.

License

Apache License

Parameter

Parameter Description
file a file potentially with non platform specific file separator characters ("/" or "\")

Return

the same file but with only File.separatorChar as the separator

Declaration

public static File fixFileSeparators(File file) 

Method Source Code

/*/*  w w  w  .  j a v  a2s.c o  m*/
    Copyright 1996-2008 Ariba, Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    $Id: //ariba/platform/util/core/ariba/util/core/FileUtil.java#24 $
 */

import ariba.util.log.Log;
import java.io.File;
import java.io.IOException;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.util.Random;
import java.util.List;

public class Main{
    /**
        Fix up file separators for platform independence. Converts
        <B>file</B> to use the appropriate separator character for the
        current platform.

        @param file a file potentially with non platform
        specific file separator characters ("/" or "\")

        @return the same <b>file</b> but with only
        File.separatorChar as the separator
        @aribaapi documented
     */
    public static File fixFileSeparators(File file) {
        if (file == null) {
            return null;
        }
        return new File(fixFileSeparators(file.getPath()));
    }
    /**
        Fix up filename separators for platform independence.
        Converts <B>filename</B> to use the appropriate separator
        character for the current platform.

        @param filename a filename potentially with non platform
        specific file separator characters ("/" or "\")

        @return the same <b>filename</b> but with only
        File.separatorChar as the separator
        @aribaapi documented
     */
    public static String fixFileSeparators(String filename) {
        if (filename == null) {
            return null;
        }
        switch (File.separatorChar) {
        case '/':
            return filename.replace('\\', File.separatorChar);
        case '\\':
            return filename.replace('/', File.separatorChar);
        default:
            Log.util.warning(2812, File.separator);
            filename = filename.replace('/', File.separatorChar);
            filename = filename.replace('\\', File.separatorChar);
            return filename;
        }
    }
}

Related

  1. fixFileSeparators(String filename)
  2. getPathSeparator()
  3. getSeparator()
  4. isWindowsPathSeparator(String p_filename)