1:
package com.dvision;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class keyInputTest {
public static void main(String[] args) throws IOException {
BufferedReader sb = null;
InputStreamReader isr = new InputStreamReader(System.in);
//把inputstreamRead转换为buffer
sb = new BufferedReader(isr);
String buffer = null;
while((buffer=sb.readLine())!=null){
System.out.println("输出的内容为:"+buffer);
}
}
}
2:
package com.dvision;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
public class FileOutputStringTest {
public static void main(String[] args) {
//printstream只适合作文本的输出
PrintStream ps=null;
try {
FileOutputStream fos = new FileOutputStream("C:\\Documents and Settings\\Administrator\\桌面\\test.txt");
//printstream封装输出流fos
ps = new PrintStream(fos);
//printsteram输出一个对象
ps.println(new FileOutputStringTest());
//指教输入,会把这些内容输入到test.txt文件中
ps.println("普通的字符串");
} catch (FileNotFoundException e) {
e.printStackTrace();
}finally{
ps.close();
}
}
}
3:
package com.dvision;
import java.io.*;
public class IOtest {
public static void main(String[] args) throws IOException {
//创建一个输入流
FileInputStream fis = new FileInputStream("C:\\Documents and Settings\\Administrator\\Workspaces\\MyEclipse 9\\TestEnum\\src\\com\\dvision\\EnumImpl.java");
//创建一个长度为1024字节的流
byte[] buff = new byte[1024];
//定义实际读取的字节数
int hasred = 0;
while((hasred=fis.read(buff))>0){
//从字符流中取出数据,并且转换成String输入
System.out.println(new String(buff,0,hasred));
}
fis.close();
}
}
4:
package com.dvision;
import java.io.FileWriter;
import java.io.IOException;
public class FileWriterTest {
public static void main(String[] args) throws IOException {
FileWriter fw = null;
try {
fw = new FileWriter("C:\\Documents and Settings\\Administrator\\桌面\\test.txt");
fw.write("这个是测试filewriter的测试txt内容!");
} catch (Exception e) {
e.printStackTrace();
}finally{
if(fw!=null){
fw.close();
}
}
}
}