当前位置: 首页>>代码示例>>Java>>正文


Java File.getName方法代码示例

本文整理汇总了Java中java.io.File.getName方法的典型用法代码示例。如果您正苦于以下问题:Java File.getName方法的具体用法?Java File.getName怎么用?Java File.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.File的用法示例。


在下文中一共展示了File.getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: moveToTargetDir

import java.io.File; //导入方法依赖的package包/类
/**
 * move artifact to target directory, return the moved artifact file path
 *
 * @param targetDirectory
 * @param artifact
 *
 * @return
 */
private Path moveToTargetDir(Path targetDirectory, Artifact artifact) {
    final File artifactFile = artifact.getFile();
    final String artifactFileName = artifactFile.getName();
    final Path targetFile = targetDirectory.resolve(artifactFileName);
    log.debug("copy {} to {}", artifactFileName, targetFile);
    if (!targetDirectory.toFile().exists()) {
        targetDirectory.toFile().mkdirs();
    }
    try {
        Files.copy(artifactFile.toPath(), targetFile, StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        final String message = String.format(
                "dependency %s:%s:%s resolved but cannot be moved to target dir: %s",
                artifact.getGroupId(),
                artifact.getArtifactId(),
                artifact.getVersion(),
                e.getMessage()
        );
        throw new DependencyResolveException(message, e);
    }
    return targetFile;
}
 
开发者ID:dshell-io,项目名称:dshell,代码行数:31,代码来源:DefaultDependencyResolver.java

示例2: Variable

import java.io.File; //导入方法依赖的package包/类
public Variable(String name, String location) {
    this.name = name;
    this.location = location;
    File f = new File(location);
    fileVar = f.exists() && f.isFile();
    if (fileVar) {
        file = f.getName();
        this.location = f.getParentFile().getAbsolutePath();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:Workspace.java

示例3: openTab

import java.io.File; //导入方法依赖的package包/类
/**
 * opens new Tab and associates it with the given {@link File}
 *
 * @param f {@link File}
 */
public void openTab(final File f) {
	SourceCodeEditor sourcePanel;
	if (f != null) {
		sourcePanel = new SourceCodeEditor(frame, f.getName());
		sourcePanel.setFile(f);
		sourcePanel.loadContent(f);
		sourcePanel.setSyntaxStyle(SyntaxStyle.resolveSyntaxStyle(f
				.getName().substring(f.getName().indexOf(".") + 1,
				f.getName().length())));
	} else {
		sourcePanel = new SourceCodeEditor(frame, "new" + newFileCounter);
		newFileCounter++;
	}
	addTabToWorkspacePane(sourcePanel);
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:21,代码来源:MainFrameController.java

示例4: getGenerationStampFromFile

import java.io.File; //导入方法依赖的package包/类
/**
 * Find the meta-file for the specified block file
 * and then return the generation stamp from the name of the meta-file.
 */
static long getGenerationStampFromFile(File[] listdir, File blockFile) {
  String blockName = blockFile.getName();
  for (int j = 0; j < listdir.length; j++) {
    String path = listdir[j].getName();
    if (!path.startsWith(blockName)) {
      continue;
    }
    if (blockFile == listdir[j]) {
      continue;
    }
    return Block.getGenerationStamp(listdir[j].getName());
  }
  FsDatasetImpl.LOG.warn("Block " + blockFile + " does not have a metafile!");
  return GenerationStamp.GRANDFATHER_GENERATION_STAMP;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:FsDatasetUtil.java

示例5: testRenameUnversionedFolder_FO

import java.io.File; //导入方法依赖的package包/类
public void testRenameUnversionedFolder_FO() throws Exception {
    // init
    File fromFolder = new File(repositoryLocation, "fromFolder");
    fromFolder.mkdirs();
    File fromFile = new File(fromFolder, "file");
    fromFile.createNewFile();
    File toFolder = new File(repositoryLocation, "toFolder");
    File toFile = new File(toFolder, fromFile.getName());

    // rename
    h.setFilesToRefresh(new HashSet<File>(Arrays.asList(fromFolder, toFolder)));
    renameFO(fromFolder, toFolder);
    assertTrue(h.waitForFilesToRefresh());

    // test
    assertFalse(fromFolder.exists());
    assertTrue(toFolder.exists());

    assertEquals(EnumSet.of(Status.UPTODATE), getCache().getStatus(fromFile).getStatus());
    assertEquals(EnumSet.of(Status.NEW_INDEX_WORKING_TREE, Status.NEW_HEAD_WORKING_TREE), getCache().getStatus(toFile).getStatus());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:FilesystemInterceptorTest.java

示例6: zipFile

import java.io.File; //导入方法依赖的package包/类
/**
 * Compactar uma arquivo.
 * @param inputFile informar o arquivo a ser compactado.
 * @param zipFilePath informar o nome e caminho zip.
 * @param iZipFile se necessário, informar uma {@link IZipFile}.
 * @throws IOException
 */
public static void zipFile(File inputFile, String zipFilePath, IZipFile iZipFile) throws IOException {
    FileOutputStream fileOutputStream = new FileOutputStream(zipFilePath);
    ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
    ZipEntry zipEntry = new ZipEntry(inputFile.getName());
    zipOutputStream.putNextEntry(zipEntry);
    FileInputStream fileInputStream = new FileInputStream(inputFile);
    FileChannel fileChannel = fileInputStream.getChannel();
    FileLock fileLock = fileChannel.tryLock(0L, Long.MAX_VALUE, /*shared*/true);
    long sizeToZip = fileInputStream.available();
    long sizeCompacted = 0;
    try {
        byte[] buf = new byte[1024];
        int bytesRead;
        while ((bytesRead = fileInputStream.read(buf)) > 0) {
            sizeCompacted += bytesRead;
            zipOutputStream.write(buf, 0, bytesRead);
            if (iZipFile != null) iZipFile.progress(sizeToZip, sizeCompacted);
        }
    } finally {
        fileLock.release();
        zipOutputStream.closeEntry();
        zipOutputStream.close();
        fileOutputStream.close();
    }
}
 
开发者ID:brolam,项目名称:OpenHomeAnalysis,代码行数:33,代码来源:OhaHelper.java

示例7: compare

import java.io.File; //导入方法依赖的package包/类
@Override
public int compare( File o1, File o2 ) {
	
	String 
			a = o1.getName(), 
			b = o2.getName();
	
	try {
		return Integer.compare( Integer.parseInt(a), Integer.parseInt( b ) );
	}
	catch (Throwable th) {
		return a.compareTo( b );
	}
}
 
开发者ID:twak,项目名称:chordatlas,代码行数:15,代码来源:AlignStandalone2d.java

示例8: process

import java.io.File; //导入方法依赖的package包/类
private static void process(Options o) {
	FlagFontFamily font = new FlagFontFamily(o.encoding);
	font.name = o.name;
	font.copyright = o.copyright;
	font.vendorId = o.vendorId;
	font.emAscent = o.emAscent;
	font.emDescent = o.emDescent;
	font.lineAscent = o.lineAscent;
	font.lineDescent = o.lineDescent;
	font.spaceWidth = o.spaceWidth;
	font.leftBearing = o.leftBearing;
	font.rightBearing = o.rightBearing;
	font.glyphBottom = o.glyphBottom;
	font.glyphHeight = o.glyphHeight;
	font.glyphWidth = o.glyphWidth;
	font.bitmapHeight = o.bitmapHeight;
	font.bitmapWidth = o.bitmapWidth;
	font.bitmapGlaze = o.bitmapGlaze;
	for (File flagFile : o.flagFiles) {
		Flag flag = readFlag(flagFile);
		if (flag == null) continue;
		String id = flag.getId();
		if (id == null || id.length() == 0) {
			id = flagFile.getName();
			int i = id.lastIndexOf('.');
			if (i > 0) id = id.substring(0, i);
		}
		boolean added = font.addFlag(id, flag, flagFile);
		if (!added) System.err.println("Warning: No encoding for " + flagFile.getName());
	}
	writeFont(o.outputFile, font);
}
 
开发者ID:kreativekorp,项目名称:vexillo,代码行数:33,代码来源:VexMoji.java

示例9: moveFile

import java.io.File; //导入方法依赖的package包/类
static File moveFile(File file, File dir){
    if (dir == null || file == null)
        return null;

    if (!dir.exists()) {
        if (dir.mkdirs()) {
            File newFile = new File(dir, file.getName());
            FileChannel outputChannel;
            FileChannel inputChannel;
            try {
                outputChannel = new FileOutputStream(newFile).getChannel();
                inputChannel = new FileInputStream(file).getChannel();
                inputChannel.transferTo(0, inputChannel.size(), outputChannel);
                inputChannel.close();

                inputChannel.close();
                outputChannel.close();

                file.delete();
            }
            catch (Exception e){
                return null;
            }

            return newFile;
        }
    }

    return file;
}
 
开发者ID:afiqiqmal,项目名称:ConcealSharedPreference-Android,代码行数:31,代码来源:FileUtils.java

示例10: getRootModelBuildLocation

import java.io.File; //导入方法依赖的package包/类
public String getRootModelBuildLocation () {
	if ( getSourceLocation()
		.startsWith( "http" ) ) {
		File f = new File( getSourceLocation()
			.substring( getSourceLocation()
				.indexOf( "/" ) ) );
		return STAGING + "/build/" + f.getName();
	} else {
		return STAGING + "/build" + getSourceLocation();
	}

}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:13,代码来源:Application.java

示例11: handle

import java.io.File; //导入方法依赖的package包/类
public Page handle(URL url) {
    String service = url.getParameter("service");
    if (service == null || service.length() == 0) {
        throw new IllegalArgumentException("Please input service parameter.");
    }
    String date = url.getParameter("date");
    if (date == null || date.length() == 0) {
        date = new SimpleDateFormat("yyyyMMdd").format(new Date());
    }
    List<List<String>> rows = new ArrayList<List<String>>();
    String directory = SimpleMonitorService.getInstance().getChartsDirectory();
    File chartsDir = new File(directory);
    String filename = directory + "/" + date + "/" + service;
    File serviceDir = new File(filename);
    if (serviceDir.exists()) {
        File[] methodDirs = serviceDir.listFiles();
        for (File methodDir : methodDirs) {
            String methodUri = chartsDir.getName() + "/" + date + "/" + service + "/" + methodDir.getName() + "/";
            rows.add(toRow(methodDir, methodUri));
        }
    }
    StringBuilder nav = new StringBuilder();
    nav.append("<a href=\"services.html\">Services</a> &gt; ");
    nav.append(service);
    nav.append(" &gt; <a href=\"providers.html?service=");
    nav.append(service);
    nav.append("\">Providers</a> | <a href=\"consumers.html?service=");
    nav.append(service);
    nav.append("\">Consumers</a> | <a href=\"statistics.html?service=");
    nav.append(service);
    nav.append("&date=");
    nav.append(date);
    nav.append("\">Statistics</a> | Charts &gt; <input type=\"text\" style=\"width: 65px;\" name=\"date\" value=\"");
    nav.append(date);
    nav.append("\" onkeyup=\"if (event.keyCode == 10 || event.keyCode == 13) {window.location.href='charts.html?service=");
    nav.append(service);
    nav.append("&date=' + this.value;}\" />");
    return new Page(nav.toString(), "Charts (" + rows.size() + ")",
            new String[] { "Method", "Requests per second (QPS)", "Average response time (ms)"}, rows);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:41,代码来源:ChartsPageHandler.java

示例12: createStepFiles

import java.io.File; //导入方法依赖的package包/类
public void createStepFiles(String dir) {
	File directory = new File(dir);
	File[] filelist = directory.listFiles();
	for (File file : filelist) {
		if (file.getName().endsWith(".txt")) {
			try {
				BufferedReader br = new BufferedReader(new FileReader(file));
				String line;
				List<String> steps = new ArrayList<String>();
				boolean in_steps = false;
				while ((line = br.readLine()) != null) {
					if (line.trim().length() == 0) {
						continue;
					} else if (line.trim().equals("Steps")) {
						in_steps = true;
					} else if (line.trim().equals("Ingredients")) {
						break;
					} else if (line.trim().startsWith("Data Parsed")) {
						break;
					} else if (in_steps) {
						steps.add(line.trim());
					}
				}
				br.close();

				BufferedWriter bw = new BufferedWriter(new FileWriter("/Users/chloe/Research/recipes/AllRecipesSteps/" + file.getName()));
				for (String step : steps) {
					List<String> sentences = Utils.splitStepSentences(step);
					for (String sentence : sentences) {
						bw.write(sentence + "\n");
					}
				}
				bw.close();
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}
	}
}
 
开发者ID:uwnlp,项目名称:recipe-interpretation,代码行数:40,代码来源:RecipeSentenceSegmenter.java

示例13: determineArchiveFormat

import java.io.File; //导入方法依赖的package包/类
/**
 * Determines the archive format of the given file based on its suffix.
 *
 * @param archiveFile the archive file
 * @return the archive format, null if not recognized or not supported
 */
private ArchiveFormat determineArchiveFormat(File archiveFile) {
	String fileName = archiveFile.getName();
	String suffix = fileName.substring(fileName.indexOf('.') + 1);
	if (fileName.endsWith("zip") || suffix.endsWith("agui")) {
		return ArchiveFormat.ZIP;
	} else if (suffix.endsWith("tar.gz")) {
		return ArchiveFormat.TAR_GZ;
	} else {
		return null;
	}
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:18,代码来源:ArchiveFileHandler.java

示例14: testMoveA2B_CreateA_FO

import java.io.File; //导入方法依赖的package包/类
public void testMoveA2B_CreateA_FO() throws Exception {
    // init
    File fileA = new File(repositoryLocation, "file");
    fileA.createNewFile();
    File folderB = new File(repositoryLocation, "folderB");
    folderB.mkdirs();
    add();
    commit();

    File fileB = new File(folderB, fileA.getName());

    // move
    h.setFilesToRefresh(new HashSet<File>(Arrays.asList(fileA, fileB)));
    moveFO(fileA, fileB);
    assertTrue(h.waitForFilesToRefresh());

    // create from file
    h.setFilesToRefresh(new HashSet<File>(Arrays.asList(fileA)));
    FileUtil.toFileObject(fileA.getParentFile()).createData(fileA.getName());
    assertTrue(h.waitForFilesToRefresh());

    // test
    assertTrue(fileB.exists());
    assertTrue(fileA.exists());

    //should be uptodate
    assertEquals(EnumSet.of(Status.UPTODATE), getCache().getStatus(fileA).getStatus());
    FileInformation info = getCache().getStatus(fileB);
    assertEquals(EnumSet.of(Status.NEW_HEAD_INDEX, Status.NEW_HEAD_WORKING_TREE), info.getStatus());
    assertEquals(fileA, info.getOldFile());
    assertTrue(info.isRenamed());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:FilesystemInterceptorTest.java

示例15: fileName

import java.io.File; //导入方法依赖的package包/类
@Nullable
private String fileName() {
    final File file = getFile();
    return file != null ? file.getName() : null;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:6,代码来源:Signature.java


注:本文中的java.io.File.getName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。