class test1{
public static void main(String[] args) throws IOException {
FileInputStream fi=new FileInputStream("D:/demo.txt");
int n=fi.available();
byte b[]=new byte[n];
while(fi.read(b)!=-1){
System.out.println(new String(b));
}
fi.close();
}
}
请问这段代码是什么意思,请同志们把它的执行步骤说明下。、
public static void main(String[] args) throws IOException {
FileInputStream fi=new FileInputStream("D:/demo.txt");
int n=fi.available();
byte b[]=new byte[n];
while(fi.read(b)!=-1){
System.out.println(new String(b));
}
fi.close();
}
}
请问这段代码是什么意思,请同志们把它的执行步骤说明下。、
解决方案 »
- JAVA替换中文空格
- *********JAVA 自动更新 **************
- JDK1.5安装问题
- 请问:com.mkjdelove.www.ScribllePane1不是抽象的,未能覆盖java.awt.event.MouseLister中的抽象方法mouseClcked(java.awt.event.MouseEv
- 关于JAR打包
- (入门级)字符串数组的使用
- JAVA 中String转换为 int 类型问题
- 谁有 ItelliJ IDEA 3.0.2 的用户名 密码 或是 注册机亚 谢谢
- 如何用java实现定时器功能?
- 请问可不可以显示一个html源代码的字符串
- java 保存 窗口对象
- 新手学java,求教,谢谢!
class test1{
public static void main(String[] args) throws IOException {
FileInputStream fi=new FileInputStream("D:/demo.txt");
int n=fi.available();//demo.txt文件大小
byte b[]=new byte[n];//创建n个长度的字节数组
while(fi.read(b)!=-1){//读取demo.txt文件,存入b中。如果fi.read(b)返回-1,表示没有数据
System.out.println(new String(b));//把字节数组转换成字符串打印出来
}
fi.close();
}
}
但问题是,它最后为什么要用 new String(b)来显示内容呢?
{ public static void main(String[] args) throws IOException
{ FileInputStream fi=new FileInputStream("D:/demo.txt"); //创建一个对象
int n=fi.available();读取"D:/demo.txt"输入流字节数的估计值
byte b[]=new byte[n];//把txt文件以字节的形式存入byte[] 数组
while(fi.read(b)!=-1)//直到把数组当中的字节全部读完,读到-1时,就说明读完了
{ System.out.println(new String(b)); } //以字符串的形式把txt文件输出来
fi.close(); } }//关闭流
Constructs a new String by decoding the specified array of bytes using the platform's default charset.
谢谢大家的帮助。!