Java 檔案操作

2021-09-23 22:56:22 字數 840 閱讀 2233

private jfilechooser chooser;

filenameextensionfilter filter = new filenameextensionfilter("allowed file", "txt","jar");

chooser.setfilefilter(filter);

intvalue = chooser.showopendialog(testopen.this);

file file = chooser.getselectedfile();

system.out.println(file.getabsolutepath());

}

如果要開啟多個檔案該怎麼做呢?

chooser.setfileselectionmode(jfilechooser.files_and_directories);

chooser.setmultiselectionenabled(true);

int value = chooser.showopendialog(testopen.this);

file file = chooser.getselectedfiles();

for (int i = 0

; i < file.length; i++)

}

向儲存檔案這種操作一定要記得檢查異常,稍有不慎就出錯了。其實無非是呼叫一下createnewfile方法而已。

try 

}} catch (headles***ception e1) catch (ioexception e1)

java 檔案操作

複製檔案 param fromfilepath string 目標檔案 param tofilepath string 儲存檔案的路徑 return boolean 複製成功 true 出錯 false public static boolean copyfile string fromfilepa...

java 檔案操作

public class documentutil else else copyfinished this.copyfolder startfile,desfile return copyfinished 顯示目錄下所有檔案ming public static file getdocuments s...

Java 檔案操作

private jfilechooser chooser filenameextensionfilter filter new filenameextensionfilter allowed file txt jar chooser.setfilefilter filter intvalue cho...