本文整理汇总了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;
}
示例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();
}
}
示例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);
}
示例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;
}
示例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());
}
示例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();
}
}
示例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 );
}
}
示例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);
}
示例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;
}
示例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();
}
}
示例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> > ");
nav.append(service);
nav.append(" > <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 > <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);
}
示例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();
}
}
}
}
示例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;
}
}
示例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());
}
示例15: fileName
import java.io.File; //导入方法依赖的package包/类
@Nullable
private String fileName() {
final File file = getFile();
return file != null ? file.getName() : null;
}