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();
}
}
}
解决方案 »
- 在学完了java的基础语法后,该学类库了吧
- Applet中能不能看到每次循环被画到applet上的那个点呢?
- 请问如何判断一个字串是另一个字串的子串?
- JAVA中的MOUSE雙擊事件(絕對原創,絕對有用)
- 利用java的sax解析xml
- NTEXT字段的特殊字符更新问题
- 【输入求助帖】我写了一个关于根据读入参数不同判断的程序
- SWING高手请进,在线等待,急急急!!!
- java里,是否可以根据一个日期,知道是星期几呢???谢谢
- 我的string 输入格式应为“yyyy/mm/dd hh:mm:ss",我怎么判断该string是否合法?
- 各位朋友,如何修改JFrame标题栏中图标?
- 高手才进来,ServerSocket传送字节丢失的问题
楼主是不是那儿弄错了
那行的意思是把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',请写出输出结果,并解释原因
第二次输入回车,请写出输出结果,并解释原因
================================================
给个结果吧...