Here you can find the source of formatPathName(Path path)
Parameter | Description |
---|---|
path | server path |
Parameter | Description |
---|---|
IOException | an exception |
public static final String formatPathName(Path path) throws IOException
//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); } }