在测试过程中需要把从A文件夹内的图片都复制到其他文件夹中去,这就涉及到了文件的复制

private static void copyFile(File oldFile, String newFilePath) {
		int byteread = 0;
		InputStream inStream = null;
		FileOutputStream fs = null;
		String oldPath = oldFile.getAbsolutePath();
		try {
			inStream = new FileInputStream(oldPath);
			fs = new FileOutputStream(newFilePath);
			byte[] buffer = new byte[1444];
			while ((byteread = inStream.read(buffer)) != -1) {
				fs.write(buffer, 0, byteread);
			}
		} catch (Exception e) {
			System.out.println("复制单个文件操作出错");
			e.printStackTrace();
		} finally {
			try {
				inStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

发表评论

电子邮件地址不会被公开。 必填项已用*标注