文章会有【原创】或者【转载】标示,部分来自Google Baidu的学习结果 {Java/PHP/Python/Ruby/Go}

Java 在学习四十【原创】  


System.in

System.out


package ioJava;


public class Test10 {


public static void main(String[] args) {

try {

byte[] b = new byte[1000];

System.out.println("请输入...");

int bytes = System.in.read(b, 0, b.length);

String s = new String(b, 0, bytes);

System.out.println(s);

} catch (Exception e) {

e.printStackTrace();

}

}


}


package ioJava;


import java.io.FileOutputStream;

import java.io.PrintStream;

import java.io.PrintWriter;


public class Test11 {


public static void main(String[] args) {

try {

PrintStream ps = new PrintStream(

new FileOutputStream("/Users/houhuiyang/Web/test.log", true));

ps.println("测试1");

ps.close();

PrintWriter ps1 = new PrintWriter(

new FileOutputStream("/Users/houhuiyang/Web/test.log", true));

ps1.write("ps1写入");

ps1.close();

} catch(Exception e) {

e.printStackTrace();

}

}


}


字符流:(文本的操作)

输入流 Reader

InputStreamReader

FileReader

BufferReader readline】没有换行

输出流 Writer

OutputStreamWriter

FileWriter

BufferWriter writenewLIne 进行换行

package ioJava;


import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;


public class class12 {


public static void main(String[] args) {

try {

// InputStreamReader in = new InputStreamReader(

// new FileInputStream("/Users/houhuiyang/Web/test.log"), "utf-8");

//

OutputStreamWriter out = new OutputStreamWriter(

new FileOutputStream("/Users/houhuiyang/Web/test.log", true), "utf-8");

// int c;

// while((c = in.read()) != -1) {

// System.out.print((char) c);

out.write("安安\n");

out.flush();

// }

// in.close();

out.close();

} catch(Exception e) {

e.printStackTrace();

}

}


}



package ioJava;


import java.io.FileReader;

import java.io.FileWriter;


public class Test13 {


public static void main(String[] args) {

try {

FileReader fr = new FileReader("/Users/houhuiyang/Web/test.log");

FileWriter fw = new FileWriter("/Users/houhuiyang/Web/test1.log");

char[] cs = new char[1000];

int chars;

while((chars = fr.read(cs, 0, cs.length)) != -1) {

fw.write(cs, 0, chars);

fw.flush();

}

fr.close();

fw.close();

} catch (Exception e) {

e.printStackTrace();

}

}


}


package ioJava;


import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

import java.io.PrintWriter;


public class Test15 {


public static void main(String[] args) {

try {

BufferedReader br = new BufferedReader(

new InputStreamReader(System.in));

PrintWriter pw = new PrintWriter(

new OutputStreamWriter(System.out), true);

while (true) {

String string = br.readLine();

//System.out.println(string);

pw.println(string);

if ("end".equals(string)) {

break;

}

}

} catch (Exception e) {

e.printStackTrace();

}

}


}