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); }
}
}
这个东西的返回值不明白哦,说是读取一个char,然后返回这个char的int型,那我输入111回车的时候,最后的应该是回车,还是1呢?
你理解错了一点!System.in.read(b); 这个方法的返回值是 你读取到的字符数量!!!System.in.read(); 这个方法才是 :说是读取一个char,然后返回这个char的int型
len - 要写入的字符数