write(byte[] b, int off, int len) 将指定 byte 数组中从偏移量 off 开始的 len 个字节写入此输出流 红字是什么意思?int count;
byte b[] = new byte[512];
count = System.in.read(b);
FileOutputStream rt = new FileOutputStream("wren4256.txt");
rt.write(b,0,count);
上面的程序,当我输入111回车的时候,count的值为5,怎么回事完整程序:
import java.util.Date;
import java.text.SimpleDateFormat;
import java.io.*;
public class wrenwren
{
public static void main(String args[]) throws IOException
{
try{
//InputStreamReader isr = new InputStreamReader(System.in);
//BufferedReader br = new BufferedReader(isr); System.out.println("何か入力してください:");
int count;
byte b[] = new byte[512];
count = System.in.read(b);
FileOutputStream rt = new FileOutputStream("wren4256.txt");
System.out.print("**************************************count:"+count);
rt.write(b,0,count);
System.out.println("成功");
File ft = new File("wren4256.txt");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM大鵬dd日hh時mm分");
System.out.println("getPath"+ft.getPath());
System.out.println("getAbsolutePath" + ft.getAbsolutePath());
System.out.println("getName" + ft.getName());
System.out.println("getParent" + ft.getParent());
System.out.println("length" + ft.length());
System.out.println("lastModified" + sdf.format(new Date(ft.lastModified())));
System.out.println("list" + ft.list());
rt.close();
}
catch (IOException e) { System.out.println(e); }
catch (Exception e) { System.out.println(e); }
}
}
byte b[] = new byte[512];
count = System.in.read(b);
FileOutputStream rt = new FileOutputStream("wren4256.txt");
rt.write(b,0,count);
上面的程序,当我输入111回车的时候,count的值为5,怎么回事完整程序:
import java.util.Date;
import java.text.SimpleDateFormat;
import java.io.*;
public class wrenwren
{
public static void main(String args[]) throws IOException
{
try{
//InputStreamReader isr = new InputStreamReader(System.in);
//BufferedReader br = new BufferedReader(isr); System.out.println("何か入力してください:");
int count;
byte b[] = new byte[512];
count = System.in.read(b);
FileOutputStream rt = new FileOutputStream("wren4256.txt");
System.out.print("**************************************count:"+count);
rt.write(b,0,count);
System.out.println("成功");
File ft = new File("wren4256.txt");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM大鵬dd日hh時mm分");
System.out.println("getPath"+ft.getPath());
System.out.println("getAbsolutePath" + ft.getAbsolutePath());
System.out.println("getName" + ft.getName());
System.out.println("getParent" + ft.getParent());
System.out.println("length" + ft.length());
System.out.println("lastModified" + sdf.format(new Date(ft.lastModified())));
System.out.println("list" + ft.list());
rt.close();
}
catch (IOException e) { System.out.println(e); }
catch (Exception e) { System.out.println(e); }
}
}
解决方案 »
- 关于eclipse的一个问题。
- 做成可执行的jar包后,点击运行后,发现图片不能显示
- 100分求SCJP 1.4(310-025,SL-275) 中文题库
- List问题!
- java中有无类似c#中一样的Dispose方法用于手动释放对象?
- 在java中像ActionListener这样的接口类(在java帮助文档里面有的)有哪些,举些常用的,说明用途,谢谢!!
- 你精通正则表达式吗?不妨进来瞧瞧!
- 怎么取DOUBLE型变量的值只到小数点后一位啊!
- 怪事天天有,今天特别多.怎么我的applet预览没问题,用浏览器打开就不行了?(在线等待)
- double类型的转换,在线等候
- jcombobox里面的文本怎么根据窗口大小自动换行
- 请问下开发java C/S结构的系统要用到哪些主要技术啊?
这个东西的返回值不明白哦,说是读取一个char,然后返回这个char的int型,那我输入111回车的时候,最后的应该是回车,还是1呢?
你理解错了一点!System.in.read(b); 这个方法的返回值是 你读取到的字符数量!!!System.in.read(); 这个方法才是 :说是读取一个char,然后返回这个char的int型
len - 要写入的字符数