JAVA基础补漏--文件读取
public class Test2 {
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("1.txt");
int len = 0;
byte[] bytes = new byte[200];
while ((len = fis.read(bytes)) != -1)
{
System.out.println(len);
System.out.println(new String(bytes,0,len));
}
}
}
文件复制
public class Test2 {
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("C:\\sdcs\\1.png");
FileOutputStream fos = new FileOutputStream("D:\\sdcs\\1.png");
int len = 0;
byte[] bytes = new byte[1024];
while ((len = fis.read(bytes)) != -1)
{
fos.write(bytes,0,len);
}
fos.close();
fis.close();
}
}