import java.io.*;
public class InputStream { public static void main(String[] args) throws Exception
{
byte [] b = "abc1dsa".getBytes();
FileOutputStream out = new FileOutputStream("text1.txt");
out.write(b);
out.close();
/*byte buf[] = new byte[1024];
File f = new File("FileSteam.txt");
FileInputStream in = new FileInputStream(f);
in.read(buf);
System.out.println(new String(buf,0,buf.length));*/
File f = new File("text1.txt");
FileInputStream in = new FileInputStream(f);
while((in.read())!=-1);//while(ch!=-1); //这里错了
System.out.println(in.read());
in.close();
}}这个程序打印的是-1 我知道是while循环的in.read方法出错了 难道不是读一个字符吗
public class InputStream { public static void main(String[] args) throws Exception
{
byte [] b = "abc1dsa".getBytes();
FileOutputStream out = new FileOutputStream("text1.txt");
out.write(b);
out.close();
/*byte buf[] = new byte[1024];
File f = new File("FileSteam.txt");
FileInputStream in = new FileInputStream(f);
in.read(buf);
System.out.println(new String(buf,0,buf.length));*/
File f = new File("text1.txt");
FileInputStream in = new FileInputStream(f);
while((in.read())!=-1);//while(ch!=-1); //这里错了
System.out.println(in.read());
in.close();
}}这个程序打印的是-1 我知道是while循环的in.read方法出错了 难道不是读一个字符吗
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货