import java.io.File;
public class FileDemonstration
{
public void analyzePath( String path )
{
File name = new File(path);
if ( name.exists() )
{
System.out.printf
("%s%s\n%s\n%s\n%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s",
name.getName(),"存在",
(name.isFile()?"是個檔案":"不是個檔案"),
(name.isDirectory()? "是個資料夾":"不是個資料夾"),
(name.isAbsolute()? "是個絕對的路徑":"不是個絕對的路徑"),
"最後修改時間:",name.lastModified(),
"長度:",name.length(),
"路徑:", name.getPath(),
"絕對路徑:",name.getAbsolutePath(),
"上一層:",name.getParent()
);
if( name.isDirectory() )
{
String directory[] = name.list();
System.out.println("\n\n裡面有的檔案或資料夾:\n");
for ( String directoryName : directory )
System.out.printf("%s\n", directoryName );
}
}
else
{
System.out.printf("%s %s", path, "不存在");
}
}
}
import java.util.Scanner;
public class FileDemonstrationTest
{
public static void main ( String args[] )
{
Scanner input = new Scanner( System.in );
FileDemonstration application = new FileDemonstration();
System.out.print("在這邊輸入目錄或檔案名:");
application.analyzePath( input.nextLine() );
}
}
留言列表