Java File Name Get getFilename(File file)

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

Description

On Windows machines the path contains "\\", however, when converted to a String, this becomes "\".

License

Open Source License

Declaration

public static String getFilename(File file) 

Method Source Code


//package com.java2s;
/*/*from w  w w  .j a  va 2s .c o  m*/
 * Copyright 2007, 2012 Stephen Fisher and Junhyong Kim, University of
 * Pennsylvania.
 *
 * This file is part of Glo-DB.
 * 
 * Glo-DB is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Glo-DB is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Glo-DB. If not, see <http://www.gnu.org/licenses/>.
 *
 * @(#)GUIUtils.java
 */

import java.io.File;

public class Main {
    /**
     * On Windows machines the path contains "\\", however, when
     * converted to a String, this becomes "\".  So we are doubling
     * them here, to preserver the "\\".
     */
    public static String getFilename(File file) {
        return file.getAbsolutePath().replaceAll("\\\\", "\\\\\\\\");
    }
}

Related

  1. getFileName(File file)
  2. getFileName(File file)
  3. getFilename(File file)
  4. getFileName(File file)
  5. getFileName(File file)
  6. getFilename(File file)
  7. getFilename(File file)
  8. getFileName(File file)
  9. getFileName(File file)