synchronized(obj) { } 进入时,将obj设为非触发状态,退出时,将obj设为触发状态。 synchronized函数锁定的对象是this对象。 wait notify notifyAll查资料 if(obj instanceof MyClass) { } Properties类是Hashtable的子类。增加了将Hashtable对象中的关键字和值保存到文件和从文件中读取关键字和值到Hashtable对象中的方法。 SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日"); try { Date d = sdf1.parse("2003-03-15"); sdf2.format(d); } Timer和TimerTask Timer的schedule方法 Timer.schedule(TimerTask task, long delay); Timer.schedule(TimerTask task, Date time); Timer.schedule(TimerTask task, long delay, long period); Timer.schedule(TimerTask task, Date firstTime, long period); TimerTask类实现了Runnable接口,要执行的任务由它里面实现的run方法来完成 File类是IO包中唯一代表磁盘文件本身信息的类,而不是文件中的内容。 流类分为两个大类:节点流类和过滤流类。 文件、网络、内存、管道 InputStream是一个抽象类,InputStream类的方法: int read(); int read(byte[] b); int read(byte[] b, int off, int len); int available(); OutputStream类的方法: void write(int b); void write(byte[] b); void write(byte[] b, int off, int len); FileInputStream inOne = new FileInputStream("hello.test"); or File f = new File("hello.test"); FileInputStream inTwo = new FileInputStream(f); FileOutputStream与FileInputStream的构造函数一样。 PipedInputStream与PipedOutputStream类 PipedWriter与PipedReader类 ByteArrayInputStream与ByteArrayOutputStream类 ============================ DataInputStream与DataOutputStreamd类 ObjectInputStream与ObjectOutputStream类 import java.net.*; public class Sender { public static void main(String[] args) throws Exception { DatagramSocket ds = new DatagramSocket(); byte [] buf = "中国人们abc".getBytes(); DatagramPacket dp = new DatagramPacket(buf, buf.length, InetAddress.getByName("127.0.0.1"), 88); ds.send(dp); ds.close(); } } import java.net.*; public class Receiver { public static void main(String[] args) throws Exception { byte[] buf = new byte[1024]; DatagramSocket ds = new DatagramSocket(88, InetAddress.getByName("127.0.0.1")); DatagramPacket dp = new DatagramPacket(buf, buf.length); ds.receive(dp); ds.close(); System.out.println(new String(dp.getData(), 0, dp.getLength())); } } URL、URLDecoder、URLEncoder、URLConnection、HttpURLConnection
java1
最新推荐文章于 2024-07-17 21:23:40 发布