java.io.File#getParent ( )源码实例Demo

下面列出了java.io.File#getParent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk8u   文件: SunFontManager.java
private PhysicalFont findOtherDeferredFont(String name, int style) {
    for (String fileName : deferredFontFiles.keySet()) {
        File file = new File(fileName);
        String dir = file.getParent();
        String fname = file.getName();
        if (dir != null &&
            dir.equals(jreFontDirName) &&
            jreLucidaFontFiles.contains(fname)) {
            continue;
        }
        PhysicalFont physicalFont = initialiseDeferredFont(fileName);
        if (physicalFont != null &&
            (physicalFont.getFontName(null).equalsIgnoreCase(name) ||
            physicalFont.getFamilyName(null).equalsIgnoreCase(name)) &&
            physicalFont.style == style) {
            return physicalFont;
        }
    }
    return null;
}
 
源代码2 项目: sonar-ruby-plugin   文件: PathResolverTest.java
@Before
public void setUp() throws Exception {
    URL filePath = PathResolverTest.class.getClassLoader().getResource("./test_controller.rb");
    existingFile = new File(filePath.toURI());
    String parentPath = existingFile.getParent();

    this.sensorContext = SensorContextTester.create(new File(parentPath));
    this.sensorContext.settings().setProperty("path key", "test_controller.rb");

    DefaultInputFile file =
        new DefaultInputFile("", "test_controller.rb")
            .setLanguage(Ruby.LANGUAGE_KEY);

    this.sensorContext.fileSystem().add(file);

    this.resolver = new PathResolver();
}
 
源代码3 项目: gemfirexd-oss   文件: ShellCommandsDUnitTest.java
public void testHistoryWithFileName() {
  Gfsh gfshInstance = Gfsh.getCurrentInstance();

  if (gfshInstance == null) {
    fail("In testHistory command gfshInstance is null");
  }

  String historyFileName = gfshInstance.getGfshConfig().getHistoryFileName();
  File historyFile = new File(historyFileName);
  String fileName = historyFile.getParent();
  fileName = fileName + File.separator + getClass().getSimpleName() + "_" + getName() + "-exported.history";
  
  String command = "history --file="+fileName;
  CommandResult cmdResult = executeCommand(command);

  if (cmdResult != null) {
    assertEquals(Result.Status.OK, cmdResult.getStatus());
  } else {
    fail("testHistory failed");
  }    
}
 
源代码4 项目: openjdk-jdk8u-backup   文件: GtkFileDialogPeer.java
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
源代码5 项目: Aria   文件: HttpDFileInfoTask.java
/**
 * 重命名文件
 */
private void renameFile(String newName) {
  if (TextUtils.isEmpty(newName)) {
    ALog.w(TAG, "重命名失败【服务器返回的文件名为空】");
    return;
  }
  ALog.d(TAG, String.format("文件重命名为:%s", newName));
  File oldFile = new File(mEntity.getFilePath());
  String newPath = oldFile.getParent() + "/" + newName;
  if (!CheckUtil.checkDPathConflicts(false, newPath, mTaskWrapper.getRequestType())) {
    ALog.e(TAG, "文件重命名失败");
    return;
  }
  if (oldFile.exists()) {
    boolean b = oldFile.renameTo(new File(newPath));
    ALog.d(TAG, String.format("文件重命名%s", b ? "成功" : "失败"));
  }
  mEntity.setFileName(newName);
  mEntity.setFilePath(newPath);
  RecordUtil.modifyTaskRecord(oldFile.getPath(), newPath, mEntity.getTaskType());
}
 
源代码6 项目: Tok-Android   文件: FileUtilsJ.java
public static String rename(String filePath, String newName) {
    if (StringUtils.isEmpty(filePath) || StringUtils.isEmpty(newName)) {
        return null;
    }
    File file = new File(filePath);
    String parent = file.getParent();
    File newFile = new File(parent, newName);
    if (newFile.exists()) {
        return null;
    }
    return file.renameTo(newFile) ? newFile.getAbsolutePath() : null;
}
 
源代码7 项目: cxf   文件: JavaToWSDLProcessor.java
protected File getOutputDir(File wsdlLocation) {
    String dir = (String)context.get(ToolConstants.CFG_OUTPUTDIR);
    if (dir == null) {
        if (wsdlLocation == null
            || wsdlLocation.getParentFile() == null
            || !wsdlLocation.getParentFile().exists()) {
            dir = "./";
        } else {
            dir = wsdlLocation.getParent();
        }
    }
    return new File(dir);
}
 
源代码8 项目: developer-studio   文件: ProjectUtils.java
public static String fileNameWithExtension(String fileName){
    File file = new File(fileName);
    if (file.isDirectory()) return fileName;
    String name = file.getName();
    final int lastPeriodPos = name.lastIndexOf('.', name.length() - 1);
    if (lastPeriodPos == -1){
        return fileName;
    }
    else {
        File nameWithoutExt = new File(file.getParent(), name.substring(0, lastPeriodPos)+"_"+name.substring(lastPeriodPos+1).toLowerCase());
        return nameWithoutExt.getPath();
    }

}
 
源代码9 项目: openjdk-8   文件: SunSDK.java
/**
 * Returns the home directory of a Java 2 SDK if the current
 * JRE is embedded in one.
 */
static String home() {
    File jreHome = new File(System.getProperty("java.home"));
    File jreParent = new File(jreHome.getParent());

    String jdwpLibName = "bin" + File.separator +
                         System.mapLibraryName("jdwp");
    File jdwpLib = new File(jreParent, jdwpLibName);
    return jdwpLib.exists() ? jreParent.getAbsolutePath() : null;
}
 
源代码10 项目: FireFiles   文件: FileUtils.java
public static boolean uncompress(File zipFile) {
    boolean success = false;
    try {
        FileInputStream fis = new FileInputStream(zipFile);
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
        ZipEntry entry;
        File destFolder = new File(zipFile.getParent(), FileUtils.getNameFromFilename(zipFile.getName()));
        destFolder.mkdirs();
        while ((entry = zis.getNextEntry()) != null) {
            File dest = new File(destFolder, entry.getName());
            dest.getParentFile().mkdirs();

            if(entry.isDirectory()) {
                if (!dest.exists()) {
                    dest.mkdirs();
                }
            } else {
                int size;
                byte[] buffer = new byte[2048];
                FileOutputStream fos = new FileOutputStream(dest);
                BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);
                while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
                    bos.write(buffer, 0, size);
                }
                bos.flush();
                bos.close();
                IoUtils.flushQuietly(bos);
                IoUtils.closeQuietly(bos);
            }
            zis.closeEntry();
        }
        IoUtils.closeQuietly(zis);
        IoUtils.closeQuietly(fis);
        success = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return success;
}
 
源代码11 项目: stendhal   文件: TilesetConverter.java
/**
 * Load tile mapping information from the standard input.
 *
 * @param path The path of the <b>map</b>. Needed for proper
 * conversion of the tileset paths.
 * @throws IOException
 */
private void loadMapping(String path) throws IOException {
	BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

	// needed for constructing the full path of the tilesets
	File f = new File(path);
	String dir = f.getParent();

	String line;
	while ((line = input.readLine()) != null) {
		String[] elements = line.split(":", -1);
		if (elements.length != 4) {
			System.err.println("Invalid line: '" + line + "'");
		} else {
			int newIndex = 0;
			if (!"".equals(elements[3])) {
				newIndex = Integer.parseInt(elements[3]);
			}

			/*
			 * Oh, yay. Tiled likes to translate the filenames internally
			 * to full paths.
			 * Great fun with java to compare the paths when the system
			 * allows no playing with directories whatsoever. We can't rely
			 * on the current directory being the same as that of the map.
			 * Building the full path from scratch, and hope for the best.
			 */
			String path1 = (new File(dir + File.separator + elements[0])).getCanonicalPath();
			String path2 = (new File(dir + File.separator + elements[2])).getCanonicalPath();

			mapping.addMapping(path1, Integer.parseInt(elements[1]), path2, newIndex);
		}
	}
}
 
源代码12 项目: openjdk-8-source   文件: Driver.java
protected File compileTestFile(File f, String testClass) {
    int rc = com.sun.tools.javac.Main.compile(new String[] { "-source", "1.8", "-g", f.getPath() });
    if (rc != 0)
        throw new Error("compilation failed. rc=" + rc);
    String path;
    if (f.getParent() != null) {
        path = f.getParent();
    } else {
        path = "";
    }

    return new File(path + testClass + ".class");
}
 
源代码13 项目: erflute   文件: Activator.java
public static String showSaveDialog(String filePath, String[] filterExtensions) {
    String dir = null;
    String fileName = null;
    if (filePath != null && !"".equals(filePath.trim())) {
        final File file = new File(filePath.trim());
        dir = file.getParent();
        fileName = file.getName();
    }
    final FileDialog fileDialog = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE);
    fileDialog.setFilterPath(dir);
    fileDialog.setFileName(fileName);
    fileDialog.setFilterExtensions(filterExtensions);
    return fileDialog.open();
}
 
源代码14 项目: openjdk-jdk8u   文件: AquaFileChooserUI.java
/**
 * Adds the directory to the model and sets it to be selected,
 * additionally clears out the previous selected directory and
 * the paths leading up to it, if any.
 */
void addItem(final File directory) {
    if (directory == null) { return; }
    if (fSelectedDirectory != null) {
        removeSelectedDirectory();
    }

    // create File instances of each directory leading up to the top
    File f = directory.getAbsoluteFile();
    final Vector<File> path = new Vector<File>(10);
    while (f.getParent() != null) {
        path.addElement(f);
        f = getFileChooser().getFileSystemView().createFileObject(f.getParent());
    };

    // Add root file (the desktop) to the model
    final File[] roots = getFileChooser().getFileSystemView().getRoots();
    for (final File element : roots) {
        path.addElement(element);
    }
    fPathCount = path.size();

    // insert all the path fDirectories leading up to the
    // selected directory in reverse order (current directory at top)
    for (int i = 0; i < path.size(); i++) {
        fDirectories.addElement(path.elementAt(i));
    }

    setSelectedItem(fDirectories.elementAt(0));

    // dump();
}
 
源代码15 项目: wisp   文件: TestUtils.java
private static List<Class> getClassList(String pack) {
    List<Class> classList = null;
    String packagePath = pack.replace(".", "/");
    if (CLASS_PATH != null) {
        String type = CLASS_PATH.getProtocol();
        if (type.equals("file")) {
            File file = new File(CLASS_PATH.getPath());
            String path = file.getParent() + CLASSES + packagePath;
            classList = getClassListByFilter(new File(path), pack);
        }
    }
    return classList;
}
 
@BeforeEach
public void before() throws IOException {
  this.errorPath = Files.createTempDir();
  this.finishedPath = Files.createTempDir();
  File inputFile = File.createTempFile("input", "file");
  File processingFlag = new File(inputFile.getParent(), inputFile.getName() + ".PROCESSING");
  this.inputFile = new InputFile(inputFile, processingFlag, 0);
  this.cleanupPolicy = create(this.inputFile, this.errorPath, this.finishedPath);
}
 
源代码17 项目: pushfish-android   文件: GradleWrapperMain.java
private static File wrapperProperties(File wrapperJar) {
    return new File(wrapperJar.getParent(), wrapperJar.getName().replaceFirst("\\.jar$", ".properties"));
}
 
源代码18 项目: dragonwell8_jdk   文件: SunFontManager.java
public
/*private*/ PhysicalFont findJREDeferredFont(String name, int style) {

    PhysicalFont physicalFont;
    String nameAndStyle = name.toLowerCase(Locale.ENGLISH) + style;
    String fileName = jreFontMap.get(nameAndStyle);
    if (fileName != null) {
        fileName = jreFontDirName + File.separator + fileName;
        if (deferredFontFiles.get(fileName) != null) {
            physicalFont = initialiseDeferredFont(fileName);
            if (physicalFont != null &&
                (physicalFont.getFontName(null).equalsIgnoreCase(name) ||
                 physicalFont.getFamilyName(null).equalsIgnoreCase(name))
                && physicalFont.style == style) {
                return physicalFont;
            }
        }
    }

    /* Iterate over the deferred font files looking for any in the
     * jre directory that we didn't recognise, open each of these.
     * In almost all installations this will quickly fall through
     * because only the Lucidas will be present and jreOtherFontFiles
     * will be empty.
     * noOtherJREFontFiles is used so we can skip this block as soon
     * as its determined that its not needed - almost always after the
     * very first time through.
     */
    if (noOtherJREFontFiles) {
        return null;
    }
    synchronized (jreLucidaFontFiles) {
        if (jreOtherFontFiles == null) {
            HashSet<String> otherFontFiles = new HashSet<String>();
            for (String deferredFile : deferredFontFiles.keySet()) {
                File file = new File(deferredFile);
                String dir = file.getParent();
                String fname = file.getName();
                /* skip names which aren't absolute, aren't in the JRE
                 * directory, or are known Lucida fonts.
                 */
                if (dir == null ||
                    !dir.equals(jreFontDirName) ||
                    jreLucidaFontFiles.contains(fname)) {
                    continue;
                }
                otherFontFiles.add(deferredFile);
            }
            jreOtherFontFiles = otherFontFiles.toArray(STR_ARRAY);
            if (jreOtherFontFiles.length == 0) {
                noOtherJREFontFiles = true;
            }
        }

        for (int i=0; i<jreOtherFontFiles.length;i++) {
            fileName = jreOtherFontFiles[i];
            if (fileName == null) {
                continue;
            }
            jreOtherFontFiles[i] = null;
            physicalFont = initialiseDeferredFont(fileName);
            if (physicalFont != null &&
                (physicalFont.getFontName(null).equalsIgnoreCase(name) ||
                 physicalFont.getFamilyName(null).equalsIgnoreCase(name))
                && physicalFont.style == style) {
                return physicalFont;
            }
        }
    }

    return null;
}
 
源代码19 项目: jasperreports   文件: XlsxDataSourceApp.java
/**
 *
 */
public void odt() throws JRException
{
	long start = System.currentTimeMillis();
	File sourceFile = new File("build/reports/XlsxDataSourceReport.jrprint");

	JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);

	File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".odt");
	
	JROdtExporter exporter = new JROdtExporter();
	
	exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
	exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile));
	
	exporter.exportReport();

	System.err.println("ODT creation time : " + (System.currentTimeMillis() - start));
}
 
源代码20 项目: jasperreports   文件: ChartThemesApp.java
/**
 *
 */
public void pptx() throws JRException
{
	long start = System.currentTimeMillis();
	File sourceFile = new File("build/reports/AllChartsReport.jrprint");

	JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);

	File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".pptx");
	
	JRPptxExporter exporter = new JRPptxExporter();
	
	exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
	exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile));

	exporter.exportReport();

	System.err.println("PPTX creation time : " + (System.currentTimeMillis() - start));
}