Java tutorial
//package com.java2s; //License from project: Apache License import java.io.File; public class Main { /** * Format file name. * If it's a directory, modify it like "/x/x/"; * else modify it like "/x/x". */ public static String getPathRuled(File file) { if (file == null) { return ""; } if (file.isDirectory()) { return file.getPath() + "/"; } return file.getPath(); } /** * Format file name. * If it's a directory, modify it like "/x/x/"; * else modify it like "/x/x". * @param file_str The file path. */ public static String getPathRuled(String file_str) { if (file_str == null) { return ""; } return getPathRuled(new File(file_str)); } }