import java.io.*;public class WriteFileDemo
{
public static void main(String[] args)throws IOException
{
byte[] somebyte={'a','b','c'};
String hello="hello";
FileOutputStream out=new FileOutputStream("WriteFileDemo.tmp");
if(out!=null)
{
System.out.println("Begin to write to file");
out.write(somebyte);
String str=new String(somebyte,0);
System.out.println("write bytes:"+somebyte+" or write string:"+str);
for(int i=0;i<hello.length();i++)//为什么要这行和下一行才能输入hello这个单词?
    out.write(hello.charAt(i));
System.out.println("write the string hello:"+hello);
out.close();
}
}
}

解决方案 »

  1.   

    System.out.println("write the string hello:"+hello);就是这行中的hello为什么要上面for语言那两行才能将其输出?
      

  2.   

    不会啊,不要拿两行一样能输出hello啊
    楼主是不是那儿弄错了
      

  3.   

    那有可能是你上面一行写错了,然后就执行不了了!
    那行的意思是把string逐个转化为byte
      

  4.   

    不可能有错的,我去掉for那两行也可以执行的,但hello就输不出来```
      

  5.   

    FileOutputStream 只支持字节读写
      

  6.   

    我的一道面试题
    public class inchar
    {
    public static void main(String[] args) throws Exception
    {
    System.out.println("请输入一个字符");
    char ch=(char)System.in.read();
    System.out.println("你输入的字符是"+ch+"好玩么");
    }
    }
    第一次输入'a',请写出输出结果,并解释原因
    第二次输入回车,请写出输出结果,并解释原因
      

  7.   

    我的一道面试题
    public class inchar
    {
    public static void main(String[] args) throws Exception
    {
    System.out.println("请输入一个字符");
    char ch=(char)System.in.read();
    System.out.println("你输入的字符是"+ch+"好玩么");
    }
    }
    第一次输入'a',请写出输出结果,并解释原因
    第二次输入回车,请写出输出结果,并解释原因
    ================================================
    给个结果吧...