//判斷使用者輸入路徑位置為檔案或是資料夾

import java.io.*;
import javax.swing.*;
class FileSample
{
public static void main(String[] args)
{
String msg, fname, fpath;
fpath = JOptionPane.showInputDialog("請輸入檔名");
File fin = new File(fpath);
fname = fin.getName();
long len = fin.length();
msg = "檔案名稱: " + fname;
if(fin.isFile() == true)
{
msg+="是一個檔案.";
}
else if(fin.isDirectory() == true)
{
msg+="是一個目錄.";
}
else
{
JOptionPane.showMessageDialog(null, "無此檔案或目錄~");
System.exit(0);
}
JOptionPane.showMessageDialog(null,
msg + "\n檔案長度" + String.valueOf(len));
}
}
arrow
arrow
    全站熱搜

    Neo Chao 發表在 痞客邦 留言(0) 人氣()