java例程练习(多线程的两种创建方式)

摘要: //接口------推荐public class Test { public static void main(String[] args) { Runner1 r = new Runner1(); //r.run();------->不是多线程,只是方法调用 Thread t = new Thread(r); t.start();//必须调用线程类的start()方法 //也可以这样: //new Thread(new Runner1()).start(); for(int i = 0; i < 100; i++) { System.out.pri... 阅读全文
posted @ 2012-05-04 22:26 Yours风之恋 阅读(170) 评论(0) 推荐(0) 编辑

java例程练习(对象流)

摘要: import java.io.*;// transient 关键字// serializable 接口// externalizable 接口public class Test { public static void main(String[] args) throws Exception{ T t = new T(); t.k = 8; FileOutputStream fos = new FileOutputStream("C:/java/testobjectio.txt"); ObjectOutputStream oos = new ObjectOutputStre 阅读全文
posted @ 2012-05-04 17:31 Yours风之恋 阅读(125) 评论(0) 推荐(0) 编辑

java例程练习(打印流)

摘要: import java.util.*;import java.io.*;//简单的日志功能public class Test { public static void main(String[] args) { String s = null; BufferedReader br = new BufferedReader ( new InputStreamReader(System.in));//标准输入 try { FileWriter fw = new FileWriter("C:/java/logfile.txt",true); PrintWr... 阅读全文
posted @ 2012-05-03 22:17 Yours风之恋 阅读(143) 评论(0) 推荐(0) 编辑

java例程练习(数据流)

摘要: import java.io.*;public class Test { public static void main(String[] args) { // 字节数组(内存)--------baos----===>==dos===>===程序 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); System.out.println(bais.available());//可以读的字节数 DataInputStream dis = new DataInp... 阅读全文
posted @ 2012-05-03 21:01 Yours风之恋 阅读(159) 评论(0) 推荐(0) 编辑

java例程练习(转换流)

摘要: import java.io.*;public class Test { public static void main(String[] args) { try { OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("C:/java/char.txt")); osw.write("microsoftibssunapplehp"); System.out.println(osw.getEncoding());//文本编码 osw.close(); //加了true 可 阅读全文
posted @ 2012-05-03 20:24 Yours风之恋 阅读(150) 评论(0) 推荐(0) 编辑

java例程练习(东软笔试题[n阶平面魔方])

摘要: import java.util.Scanner;public class MoFang { public static void main(String[] args) { System.out.println("输入行(列)数:"); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] a = new int[n][n]; int i = 0; int j = n / 2; //算法精要 for (int k = 1; k <= n * n; k++) { a[i][j] = k; 阅读全文
posted @ 2012-05-03 19:52 Yours风之恋 阅读(179) 评论(1) 推荐(0) 编辑

java例程练习(缓冲流)

摘要: import java.io.*;public class Test { public static void main(String[] args) { try { FileInputStream fis = new FileInputStream("C:/java/Test.java"); BufferedInputStream bis = new BufferedInputStream(fis); int c = 0; System.out.println(bis.read()); System.out.println(bis.read()); ... 阅读全文
posted @ 2012-05-02 16:59 Yours风之恋 阅读(129) 评论(0) 推荐(0) 编辑

java例程练习(字符流)

摘要: import java.io.*;public class TestFileReader { public static void main(String[] args) { FileReader fr = null; int c = 0; try { fr = new FileReader("C:/java/Test.java"); while((c = fr.read()) != -1) { System.out.print((char)c); } fr.close(); } catch (FileNotFoundException e) { Sys... 阅读全文
posted @ 2012-05-01 22:18 Yours风之恋 阅读(127) 评论(0) 推荐(0) 编辑

Java例程练习(字节流)

摘要: import java.io.*;public class Test { public static void main(String[] args) { int b = 0; FileInputStream in = null; try { in = new FileInputStream("C:/java/Test.java"); } catch (FileNotFoundException e) { System.out.println("找不到指定文件"); System.exit(-1); } try { long num = 0... 阅读全文
posted @ 2012-05-01 21:37 Yours风之恋 阅读(140) 评论(0) 推荐(0) 编辑

java例程练习(泛型和自动打包、解包)

摘要: //TestArsgWords.javaimport java.util.*;public class TestArgsWords { public static void main(String[] args) { Map m = new HashMap(); for(int i = 0; i c = new ArrayList(); c.add("aaa"); c.add("bbb"); c.add("ccc"); for(int i = 0; i c2 = new HashSet (); c2.add("aaa&quo 阅读全文
posted @ 2012-05-01 15:06 Yours风之恋 阅读(208) 评论(0) 推荐(0) 编辑