try {
FileInputStream fs = new FileInputStream("e://aa.txt");
FileOutputStream fo = new FileOutputStream("e://b.txt");
byte b[] = new byte[5];
b[0] = (char) 'x';
while ((fs.read(b, 0, 512)) != -1) {
fo.write(b);
System.out.println("shoudao");
}
fs.close();
fo.close();
} catch (IOException e) {
System.out.println(e);
} catch (Exception e1) {
System.out.println(e1);
}
错误提示:
java.lang.IndexOutOfBoundsException
FileInputStream fs = new FileInputStream("e://aa.txt");
FileOutputStream fo = new FileOutputStream("e://b.txt");
byte b[] = new byte[5];
b[0] = (char) 'x';
while ((fs.read(b, 0, 512)) != -1) {
fo.write(b);
System.out.println("shoudao");
}
fs.close();
fo.close();
} catch (IOException e) {
System.out.println(e);
} catch (Exception e1) {
System.out.println(e1);
}
错误提示:
java.lang.IndexOutOfBoundsException
byte数组空间不够
fs.read(b, 0, 512)
你数组b才5个字节,怎么从0读到512个字节啊
FileInputStream fs = new FileInputStream("e://aa.txt");
FileOutputStream fo = new FileOutputStream("e://b.txt");
byte b[] = new byte[512];
b[0] = (char) 'x';
while ((fs.read(b, 0, 512)) != -1) {
fo.write(b);
System.out.println("shoudao");
}
fs.close();
fo.close();
} catch (IOException e) {
System.out.println(e);
} catch (Exception e1) {
System.out.println(e1);
}