posts - 1, comments - 4, trackbacks - 0, articles - 0

          2006年6月20日

          public static void Url() throws MalformedURLException{ File file = new File("b.txt"); URL url =null; url = file.toURL(); String dir =file.getPath(); System.out.print(file.getAbsolutePath()); file.renameTo(new File(dir,file.getName())); } public static void cope()throws IOException{ File file = new File("b.txt"); File file2 = new File("c.txt"); if(!file2.exists()){ file2.createNewFile(); } FileInputStream in = new FileInputStream(file); // InputStream in = url.openStream(); FileOutputStream out = new FileOutputStream(file2); byte[] buffer = new byte[4096]; int data; while((data = in.read(buffer))!=-1){ out.write(buffer,0,data); } in.close(); out.close(); } public static void read() throws IOException{ File file = new File("b.txt"); System.out.print("Overwrite existing file " + file.getName() +"? (Y/N): "); System.out.flush(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String readtowrite = in.readLine(); BufferedWriter ot = new BufferedWriter(new FileWriter("b.txt")); ot.write(readtowrite); ot.close(); } public static void test() throws IOException{ File file = new File("b.txt"); if(!file.exists()){ file.createNewFile(); } File file2 = new File("c.txt"); if(!file2.exists()){ file2.createNewFile(); } FileInputStream in = new FileInputStream(file); // InputStream in = url.openStream(); FileOutputStream out = new FileOutputStream(file2); byte[] buffer = new byte[4096]; int data; while((data = in.read(buffer))!=-1){ out.write(buffer,0,data); } in.close(); out.close(); } public static void compress() throws IOException{ File file = new File("b.txt"); FileInputStream in = new FileInputStream(file); String to =file.getName()+".zip"; GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream("e:/"+to)); byte[] buffer = new byte[4096]; int data; while((data = in.read(buffer))!=-1){ out.write(buffer,0,data); } in.close(); out.close(); }

          posted @ 2006-06-20 13:15 JavaDoIt 閱讀(484) | 評論 (4)編輯 收藏

          主站蜘蛛池模板: 武乡县| 扶风县| 永修县| 探索| 朝阳区| 崇左市| 南投市| 绥化市| 洛南县| 丰台区| 侯马市| 东乌珠穆沁旗| 子长县| 阳原县| 五原县| 明溪县| 光泽县| 翁牛特旗| 安陆市| 松阳县| 长治县| 新源县| 门头沟区| 静宁县| 汉川市| 隆化县| 临高县| 陈巴尔虎旗| 安平县| 浦北县| 扎兰屯市| 泸水县| 江阴市| 刚察县| 湘乡市| 图木舒克市| 富源县| 乌兰浩特市| 汝州市| 乐至县| 旬邑县|