JAVA中I/O流之字节流的使用
import java.io.*;//第一步:导入包
class test{
public static void main(String args []){
FileInputStream fis = null;//第二步:声明输入流的引用
try{
fis = new FileInputStream("f:/javasrc/from.txt");//第三步:生成输入流的对象
byte [] buffer = new byte[100];//第四步:生成一个字节数组(注意byte的大小写)
fis.read(buffer,0,buffer.length);//第五步:调用输入流对象的read方法,读取数据
String s =new String(buffer);
s = s.trim();//调用trim方法去掉字符串的首位空字符和空格
System.out.print(s);
/*for(int i=0;i<buffer.length;i++)
{
System.out.println(buffer[i]);
}*/
}
catch(Exception e){
System.out.print(e);
}
finally
}
}
浙公网安备 33010602011771号