File getName - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for File getName method.

This code example shows how to use the following methods:exists, getAbsolutePath, getName, isDirectory
    public static MixedDomainTestSupport create(String testClass, Version.AsVersion version) throws Exception {
        OldVersionCopier oldVersionCopier = OldVersionCopier.expandOldVersion(version);
        File dir = oldVersionCopier.getVersionDir(version);
 
        return new MixedDomainTestSupport(testClass, "master-config/domain.xml", "master-config/host.xml",
                "slave-configs/" + dir.getName() + "/domain/configuration/host-slave.xml", dir.getAbsolutePath());
    } 
} 

9
CodeRank
This code example shows how to use the following methods:delete, deleteOnExit, exists, getName
    protected final File fileName;
 
 
    ConfigurationFilePersistenceResource(final ModelNode model, final ConfigurationFile configurationFile,
                                         final AbstractConfigurationPersister persister) throws ConfigurationPersistenceException {
        super(model, persister);
        this.configurationFile = configurationFile;
        this.fileName = configurationFile.getMainFile();
    } 
 
    @Override 
    public void doCommit(ExposedByteArrayOutputStream marshalled) {
        final File tempFileName = FilePersistenceUtils.createTempFile(fileName);
        try { 
            try { 
                FilePersistenceUtils.writeToTempFile(marshalled, tempFileName);
            } catch (Exception e) {
                MGMT_OP_LOGGER.failedToStoreConfiguration(e, fileName.getName());
                return; 
            } 

9
CodeRank
This code example shows how to use the following methods:delete, exists, getName
 
		String location = result.get("report-location").asString();
		Assert.assertNotNull("JDR report location was null", location);
 
		// Validate report itself. 
		File reportFile = new File(location);
		Assert.assertTrue("JDR report missing, not located at " + location, reportFile.exists());
		validateJdrReportContents(reportFile);
 
		// Clean up report file 
		reportFile.delete();
	} 
 
	private void validateJdrReportContents(File reportFile) {
	    String reportName = reportFile.getName().replace(".zip","");
 
		ZipFile reportZip = null;
		try { 
			reportZip = new ZipFile(reportFile);
			validateReportEntries(reportZip, reportName);

9
CodeRank
This code example shows how to use the following methods:exists, getName, isDirectory, isFile
			} else { 
				if(param.contains("*")) {
					errString = "550 NLST does not support wildcards\r\n";
					break mainblock; 
				} 
				fileToList = new File(sessionThread.getWorkingDir(), param);
				if(violatesChroot(fileToList)) {
					errString = "450 Listing target violates chroot\r\n";
					break mainblock; 
				} else if(fileToList.isFile()) {
					// Bernstein suggests that NLST should fail when a  
					// parameter is given and the parameter names a regular  
					// file (not a directory). 
					errString = "550 NLST for regular files is unsupported\r\n";
					break mainblock; 
				}				 
			} 
			String listing;
			if(fileToList.isDirectory()) {
				StringBuilder response = new StringBuilder();

8
CodeRank
This code example shows how to use the following methods:getAbsolutePath, getName
     */ 
    public ChunkStore getChunkStore() throws IOException, DataException { 
        ChunkStore chunkStore = _getChunkStore();
 
        logger.info("WorldEdit: Using " + chunkStore.getClass().getCanonicalName()
                + " for loading snapshot '" + file.getAbsolutePath() + "'");
 
        return chunkStore;
    } 
 
    /** 
     * Get a chunk store. 
     * 
     * @return 
     * @throws IOException 
     * @throws DataException 
     */ 
    public ChunkStore _getChunkStore() throws IOException, DataException { 
        if (file.getName().toLowerCase().endsWith(".zip")) {
            try { 

8
CodeRank
This code example shows how to use the following methods:exists, getName
  @Test(timeout=1000) 
  public void testFindContainingJar() { 
    String containingJar = ClassUtil.findContainingJar(Logger.class);
    Assert.assertNotNull("Containing jar not found for Logger", 
        containingJar);
    File jarFile = new File(containingJar);
    Assert.assertTrue("Containing jar does not exist on file system", 
        jarFile.exists());
    Assert.assertTrue("Incorrect jar file" + containingJar,  
        jarFile.getName().matches("log4j.+[.]jar"));
  } 
} 
8
CodeRank
This code example shows how to use the following methods:createNewFile, getName
  } 
 
  @Test 
  public void deleteFile_shouldReturnTrue() throws IOException { 
    File filesDir = context.getFilesDir();
    File file = new File(filesDir, "test.txt");
    boolean successfully = file.createNewFile();
    assertThat(successfully).isTrue();
    successfully = context.deleteFile(file.getName());
    assertThat(successfully).isTrue();
  } 
 
  @Test 
  public void deleteFile_shouldReturnFalse() throws IOException { 
    File filesDir = context.getFilesDir();
    File file = new File(filesDir, "test.txt");
    boolean successfully = context.deleteFile(file.getName());
    assertThat(successfully).isFalse();
  } 
 
8
CodeRank
This code example shows how to use the following methods:exists, getName, lastModified, length
     * @param mediaType the media type. 
     */ 
    public void setFileEntity(final File fileEntity, final MediaType mediaType) {
        super.setMediaType(mediaType);
 
        super.setEntity(fileEntity);
        this.fileEntity = fileEntity;
 
        if (fileEntity != null) {
            FormDataContentDisposition.FormDataContentDispositionBuilder builder =
                    FormDataContentDisposition.name(getName()); 
            builder.fileName(fileEntity.getName());
            if (fileEntity.exists()) {
                builder.size(fileEntity.length());
                builder.modificationDate(new Date(fileEntity.lastModified()));
            } 
            setFormDataContentDisposition(builder.build());
        } 
    } 
 
8
CodeRank
This code example shows how to use the following methods:getName
            Arrays.sort(sheetFiles, new Comparator<File>() {
 
                public int compare(File f1, File f2) {
 
                    String o1 = f1.getName();
                    String o2 = f2.getName();
 
                    if (o1.contains("-") && o2.contains("-")) {
                        return o1.substring(0, o1.indexOf("-"))
                                .compareTo(o2.substring(0, o1.indexOf("-")));
                    } else { 
                        return o1.compareTo(o2);
                    } 
                } 
            }); 
 
            return sheetFiles;
        } 
 
        return null; 
8
CodeRank
This code example shows how to use the following methods:exists, getName, isDirectory, length
     */ 
    FilesObject (File obj, String mimeType, FilesContainer container) throws NullPointerException, NoSuchAlgorithmException, IOException
    { 
    	if (obj != null)
        { 
            if (obj.exists())
            { 
                if (!obj.isDirectory())
                { 
                    setName (obj.getName());
                    setMd5sum(FilesClient.md5Sum(obj));
                    setSize(obj.length());
                    setMimeType(mimeType);
                    setClient(container.getClient ());
                    setContainer(container.getName());
                } 
                else 
                { 
                	logger.fatal("Can not create Directories as FSObjects create a FilesContainer for this object"); 
                	throw new NullPointerException("File Object was a directory !");
8
CodeRank

Related File getName Questions & Answers:

Other File getName Examples

64:	    ContentValues values = new ContentValues(4);
65:	    long current = System.currentTimeMillis();
66:	    values.put(MediaStore.Audio.Media.TITLE, "audio" + audiofile.getName());
67:	    values.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / 1000));
68:	    values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/3gpp");

Read More

25:					HashMap<String, String> song = new HashMap<String, String>();
26:					song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4)));
27:					song.put("songPath", file.getPath());
28:	
29:					// Adding each song to SongList
-
25:					HashMap<String, String> song = new HashMap<String, String>();
26:					song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4)));
27:					song.put("songPath", file.getPath());
28:	
29:					// Adding each song to SongList

Read More

getName Method Overview
Returns the name of the file or directory denoted by this abstract pathname.
See Code Examples for other Java 8 File Methods: