Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { /** * combine two path into a single path with File.separator. * Handle all cases where the separator already exists. */ public static String pathCombine(String path1, String path2) { if (path2 == null) return path1; else if (path1 == null) return path2; path1 = path1.trim(); path2 = path2.trim(); if (path1.endsWith(File.separator)) { if (path2.startsWith(File.separator)) return path1 + path2.substring(1); else return path1 + path2; } else { if (path2.startsWith(File.separator)) return path1 + path2; else return path1 + File.separator + path2; } } }