Java tutorial
//package com.java2s; import java.io.File; import java.io.IOException; public class Main { private static File getTestDataDir() { // Search each parent directory looking for "src/google/protobuf". File ancestor = new File("."); try { ancestor = ancestor.getCanonicalFile(); } catch (IOException e) { throw new RuntimeException("Couldn't get canonical name of working directory.", e); } while (ancestor != null && ancestor.exists()) { if (new File(ancestor, "src/google/protobuf").exists()) { return new File(ancestor, "src/google/protobuf/testdata"); } ancestor = ancestor.getParentFile(); } throw new RuntimeException("Could not find golden files. This test must be run from within the " + "protobuf source package so that it can read test data files from the " + "C++ source tree."); } }