Java Path File Name nio formatPathName(Path path)

Here you can find the source of formatPathName(Path path)

Description

Format the file/diretory information as specified in RFC

License

Apache License

Parameter

Parameter Description
path server path

Exception

Parameter Description
IOException an exception

Return

formatted output

Declaration

public static final String formatPathName(Path path) throws IOException 

Method Source Code

//package com.java2s;
/*/*from w w w.  j  av a  2s .com*/
 * Copyright 2004-2005 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Locale;
import java.util.Calendar;

import java.nio.file.Path;

import java.io.IOException;
import java.nio.file.Files;

import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;

public class Main {
    /**
     * Format the file/diretory information as specified in RFC
     * @param path server path
     * @return formatted output
     * @throws IOException
     */
    public static final String formatPathName(Path path) throws IOException {
        int thisYear, node = 1;
        Locale fileLocale = new Locale("en");
        String user = "user", group = "group";
        String dateString, permission;
        GregorianCalendar fileDate = new GregorianCalendar();
        thisYear = fileDate.get(Calendar.YEAR);
        if (Files.isDirectory(path))
            permission = "d---------";
        else
            permission = "----------";
        fileDate.setTimeInMillis(Files.getLastModifiedTime(path).toMillis());
        if (thisYear == fileDate.get(Calendar.YEAR))
            dateString = (new SimpleDateFormat("MMM dd HH:mm", fileLocale).format(fileDate.getTime()));
        else
            dateString = (new SimpleDateFormat("MMM dd yyyy", fileLocale).format(fileDate.getTime()));
        return String.format("%s%5d %-9s%-9s%10d %-12s ", permission, node, user, group, Files.size(path),
                dateString);
    }
}

Related

  1. findFile(Path directoryPath, String fileName)
  2. findFile(String basePath, final String fileName)
  3. findNextFileName(Path folder, String name)
  4. findRootPathForResource(String resourceName, ClassLoader classLoader)
  5. findUpward(String filename, Path startingPath)
  6. getAbsolutePath(String fileName)
  7. getAbsolutePath(String name)
  8. getAbsolutePathName(File dir)
  9. getAllFiles(List fileNames, Path path)