最基本的JavaIO流操作代码

class Demo 
{
	public static void main(String[] args) 
	{
		//写
		File f = new File("路径名");
		FileInputStream fis = new FileInputStream(file);
		ByteArrayOutputStream bos =new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int len = 0;
		while((len = fis.read(buffer)) !=-1){
			bos.write(buffer, 0 ,  len);
		}

		//读
		File f = new File("路径名");
		FileOutputStream fos = new FileOutputStream(file);
		fos.write("haha:12345".getBytes());

	}
}

你可能感兴趣的:(最基本的JavaIO流操作代码)