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();
}
}
}
{
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();
}
}
}
楼主是不是那儿弄错了
那行的意思是把string逐个转化为byte
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',请写出输出结果,并解释原因
第二次输入回车,请写出输出结果,并解释原因
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',请写出输出结果,并解释原因
第二次输入回车,请写出输出结果,并解释原因
================================================
给个结果吧...