今天还好点,能登陆了.但是好慢,昨天压根登不上来 , 啥子情况? 在改版?
- /*
- IOStream Test
- */
- import java.io.*;
- public class IOStreamDemo {
-
- public static void main(String[] args) throws IOException {
- //fileCopy_1();
- //fileCopy_2();
- transStream();
- }
-
- /*复制一个文本文件*/
- public static void fileCopy_1() throws IOException {
- long start = System.currentTimeMillis();
- BufferedReader bufr = new BufferedReader(new FileReader("TransStreamDemo.java"));
- BufferedWriter bufw = new BufferedWriter(new FileWriter("CopyTSD.TXT"));
-
- String line = null;
-
- while((line = bufr.readLine()) != null) {
- bufw.write(line.toUpperCase());
- bufw.newLine();
- bufw.flush();
- }
-
- bufr.close();
- bufw.close();
-
- long end = System.currentTimeMillis();
- System.out.println("耗时:" + (end-start) + "毫秒");
- }
-
- /*复制一个非文本文件*/
- public static void fileCopy_2() throws IOException {
- long start = System.currentTimeMillis();
- BufferedInputStream bufis = new BufferedInputStream(new FileInputStream("1.exe"));
- BufferedOutputStream bufos = new BufferedOutputStream(new FileOutputStream("2.exe"));
-
- byte[] buf = new byte[1024*1024];
- int len = 0;
- while((len=bufis.read(buf)) != -1) {
- bufos.write(buf);
- }
-
- bufis.close();
- bufos.close();
- long end = System.currentTimeMillis();
- System.out.println("耗时:" + (end-start) + "毫秒");
- }
- /*接收键盘录入,打印到控制台*/
- public static void transStream() throws IOException {
- BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));
- BufferedWriter bufw = new BufferedWriter(new OutputStreamWriter(System.out));
-
- String line = null;
- while((line=bufr.readLine()) != null) {
- if(line.equals("over"))
- break;
- bufw.write(line);
- bufw.newLine();
- bufw.flush();
- }
- bufr.close();
- bufw.close();
- }
- }
复制代码 |
|