File import java io File import java util

  • Slides: 15
Download presentation

File類別的方法 import java. io. File; import java. util. Date; public class File. Test {

File類別的方法 import java. io. File; import java. util. Date; public class File. Test { public static void main(String[] args){ File f = new File("d: \File 3. txt"); System. out. println("f 是否存在: "+f. exists()); System. out. println("f 是否為檔案: "+f. is. File()); System. out. println("f 是否可以讀取: "+f. can. Read()); System. out. println("f 是否可以寫入: "+f. can. Write()); System. out. println("f 的實際名稱: "+f. get. Name()); System. out. println("f 的修改日期: "+new Date(f. last. Modified())); System. out. println("f 的實際大小: "+f. length()+ " Bytes"); System. out. println("f 的絕對路徑: "+f. get. Absolute. Path()); System. out. println("f 的路徑: "+f. get. Parent()); } }

文字檔複製 import java. io. *; public class Test 02 {//使用File. Reader將文字檔的內容讀入 顯示 並將讀入的內容寫入另一個檔案 public

文字檔複製 import java. io. *; public class Test 02 {//使用File. Reader將文字檔的內容讀入 顯示 並將讀入的內容寫入另一個檔案 public static void main(String[] args){ File. Reader fr; File. Writer fw; int i; try{ fr = new File. Reader("D: /File 1. txt"); //開啟串流 fw = new File. Writer("D: /File 3. txt", true); //把append設為true使每次執行後字串內容會新增到File 3. txt檔案中 while(fr. ready()){//判斷是否可以讀取檔案 i=fr. read(); //讀入字元 System. out. print((char)i); //輸出到螢幕 fw. write(i); //寫入字元 } fr. close(); //關閉串流 fw. close(); } catch(IOException ex){ System. out. println("ex. to. String()"); // } }//main }//test 02

檔案下載 import java. io. *; import java. util. *; import java. net. *; public

檔案下載 import java. io. *; import java. util. *; import java. net. *; public class Hello. World { public static void main(String[] args) throws IOException { String urlstring = args[0]; //欲下載的網址 //ftp: //ftp. cpuid. com/cpu-z_1. 66 -cn. zip; String output. File = args[1]; //下載儲存的檔案 //D: DLTest. zip File des. File =new File(output. File); if (des. File. exists()) des. File. delete(); URL url = new URL( urlstring ); URLConnection connection = url. open. Connection(); byte[] data = new byte[1]; //Input. Stream //設定接收資料流來源 , 就是要下載的網址 Buffered. Input. Stream buffered. Input. Stream = new Buffered. Input. Stream( connection. get. Input. Stream() ); //設定 儲存 要下載檔案的位置. Buffered. Output. Stream buffered. Output. Stream = new Buffered. Output. Stream(new File. Output. Stream(des. File)); while( buffered. Input. Stream. read(data) != -1) { buffered. Output. Stream. write(data); } buffered. Output. Stream. flush(); // 將緩衝區中的資料全部寫出 buffered. Input. Stream. close(); // 關閉資料流 buffered. Output. Stream. close(); System. out. println("下載完成"); } }

DJ Native Swing � The Native. Swing library allows an easy integration of some

DJ Native Swing � The Native. Swing library allows an easy integration of some native components into Swing applications, and provides some native utilities to enhance Swing's APIs. � It is composed of a framework library, and an SWT-based implementation that provides many rich components. � The key components of this SWT-based implementation are of course a rich Web Browser and a Flash player, though it also offers a Multimedia Player, an HTML Editor and a Syntax Highlighter. � The Native. Swing Demo application presents all the functionalities, along with corresponding source code.

JFlash. Player播放器實例 import java. awt. Border. Layout; import javax. swing. JFrame; import javax. swing.

JFlash. Player播放器實例 import java. awt. Border. Layout; import javax. swing. JFrame; import javax. swing. JPanel; import javax. swing. Swing. Utilities; import chrriis. dj. nativeswing. swtimpl. Native. Interface; import chrriis. dj. nativeswing. swtimpl. components. JFlash. Player; public class Simple. Flash. Example extends JPanel { public Simple. Flash. Example() { //格式[http: //www. youtube. com/v/8 pf. BI-a 2 R 8 c] super(new Border. Layout(0, 0)); JFlash. Player flash. Player = new JFlash. Player(null); flash. Player. load("http: //www. youtube. com/v/f. ES 4 xl 2 nam. Y"); add(flash. Player); } public static void main(String[] args) { Native. Interface. open(); Swing. Utilities. invoke. Later(new Runnable() { public void run() { JFrame frame = new JFrame("測試畫面"); frame. set. Default. Close. Operation(JFrame. EXIT_ON_CLOSE); frame. get. Content. Pane(). add(new Simple. Flash. Example(), Border. Layout. CENTER); frame. set. Size(800, 600); frame. set. Location. Relative. To(null); frame. set. Visible(true); } }); // Swing. Utilities. invoke. Later() } }

參考資料 � http: //www. oracle. com/technetwork/java/inde x. html � JAVA由初學邁向認證(第三版) [鄭博元, 郭芳熙著, 上奇出版社] �

參考資料 � http: //www. oracle. com/technetwork/java/inde x. html � JAVA由初學邁向認證(第三版) [鄭博元, 郭芳熙著, 上奇出版社] � Package java. io: http: //docs. oracle. com/javase/7/docs/api/java/i o/package-summary. html � The DJ Project (Rediscover the Desktop) Native Swing http: //djproject. sourceforge. net/ns/

End

End