Here you can find the source of relativeTo(File peer, String filename)
public static File relativeTo(File peer, String filename)
//package com.java2s; /* Copyright (C) 2009 Mobile Sorcery AB //from ww w . ja va 2 s . c o m This program is free software; you can redistribute it and/or modify it under the terms of the Eclipse Public License v1.0. This program 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 Eclipse Public License v1.0 for more details. You should have received a copy of the Eclipse Public License v1.0 along with this program. It is also available at http://www.eclipse.org/legal/epl-v10.html */ import java.io.File; public class Main { public static File relativeTo(File peer, String filename) { File filenameFile = new File(filename); if (filenameFile.isAbsolute()) { return filenameFile; } File dir = peer.isDirectory() ? peer : peer.getParentFile(); return new File(dir, filename).getAbsoluteFile(); } }