write(byte[] b, int off, int len) 将指定 byte 数组中从偏移量 off 开始的 len 个字节写入此输出流
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); }
}
}