import java.net.*;
String ip = InetAddress.getLocalHost().getHostAddress() ;
公告版位
目前分類:[程式語言] Java (91)
- May 17 Thu 2012 21:01
取得 目前電腦 IP
- May 13 Sun 2012 23:53
Java 在 Frame 中隱藏滑鼠
指向一個不存在的圖片將可隱藏滑鼠
setCursor(this.getToolkit().createCustomCursor(new ImageIcon("").getImage(),new Point(16, 16),""));
- May 06 Sun 2012 10:21
Collection 集合的使用
//-- HashSet----------------------------------------
//無順序,但是加入相同物件的資料 會被過濾掉
import java.util.*;
public class SetTest{
public static void main(String[] args){
HashSet hs=new HashSet();
hs.add(8);
hs.add("darban");
hs.add(3.14159);
hs.add(new Date());
- May 06 Sun 2012 09:37
程式中斷
public static void main(String [] args){
int a = 5;
if(a==5){
System.out.println("中斷啦");
return;
}
System.out.println("程式沒有中斷");
}
//-----------------------------------------------------
//-- 語法 : assert <布林值> : <輸出>;
- May 06 Sun 2012 09:23
return 注意事項
// 此方法會編譯錯誤,因為 return 可能不執行
int run(int a){
if(a > 0){
return 0;
}
}
- Apr 29 Sun 2012 14:18
JAVA 字串切割,取得 HTML 值
先建立A.txt,輸入 : <br>123<br>abc<br>456<br>
import java.io.*;
import java.util.*;
public class A{
public static void main(String [] args) throws Exception{
Scanner s = new Scanner(new File("A.txt"));
s.useDelimiter("<br>");
while(s.hasNext()){
- Apr 29 Sun 2012 11:17
JAVA 檔案下載器
import java.io.*;
import java.net.*;
public class Downloader{
public static void main(String[] args)throws IOException{
URL url=new URL("http://163.20.63.180/javaroom/midi/alas/Other/td.mid");
InputStream is=url.openStream();
FileOutputStream fos=new FileOutputStream("td.mid");
while(true){
int i=is.read();
if(i==-1)
- Apr 29 Sun 2012 10:18
JAVA 文字讀取 FileReader
import java.io.*;
public class A{
public static void main(String [] args) throws Exception{
File f = new File("gg.txt");
FileReader fr = new FileReader(f);
char [] fc = new char [(int)f.length()];
fr.read(fc);
fr.close();
String s = new String(fc);
System.out.print(s);
- Apr 29 Sun 2012 09:49
JAVA 文字新增/寫入檔案 FileWriter
//----------------------------------------------------覆蓋原有
import java.io.*;
public class A{
public static void main(String [] args) throws Exception{
FileWriter fw = new FileWriter("gg.txt");
fw.write("你好!!");
fw.close();
}
}
//---------------------------------------------------加在尾端
- Mar 11 Sun 2012 14:48
Java 專有名詞
變數(variable) = 欄位(Java官方使用) = 狀態 = 屬性
型別 : 包含 基本型別、類別