File附件复制

2023-12-29 14:12:35
File f = fileManager.getFile(newSeal.getSealFileId());
String path = SystemEnvironment.getSystemTempFolder();
File newfile = new File(path + File.separator + x.getFilename());
EcontractUtil.copyFile(f, newfile);

SystemEnvironment类

private static String systemTempFolder = null;
private static String accessPatterns = "Local";
private static String indexFilePath = null;
private static String baseFolder = null;

    public static String getSystemTempFolder() {
        if (isBlank(systemTempFolder)) {
            String filepath = null;
            if (accessPatterns.equals("Remote")) {
                if (indexFilePath != null && !indexFilePath.isEmpty()) {
                    filepath = indexFilePath + "/temporary";
                } else {
                    filepath = baseFolder + "/index/temporary";
                }
            } else {
                filepath = SystemProperties.getInstance().getProperty("ctp.temporary.folder");
            }

            systemTempFolder = getCanonicalPathAndCreate(filepath);
        }

        return systemTempFolder;
    }

private static String getCanonicalPathAndCreate(String filepath) {
        return getCanonicalPath(filepath, true);
    }


private static String getCanonicalPath(String filepath, boolean isCreate) {
        if (isBlank(filepath)) {
            return null;
        } else {
            File f = new File(filepath);

            try {
                File fc = f.getCanonicalFile();
                if (isCreate) {
                    fc.mkdirs();
                }

                return fc.getAbsolutePath();
            } catch (IOException var4) {
                return filepath;
            }
        }
    }

private static boolean isBlank(String str) {
        return str == null || str.length() == 0;
    }

EcontractUtil类
public static void copyFile(File oldfile, File newfile) throws Exception {
		FileInputStream in = new FileInputStream(oldfile);
		FileOutputStream out = new FileOutputStream(newfile);
		byte[] buff = new byte[1024];
		int n = 0;
		while ((n = in.read(buff)) != -1) {
			out.write(buff, 0, n);
		}
		out.flush();
		in.close();
		out.close();
	}

文章来源:https://blog.csdn.net/luojiawen208/article/details/135274713
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。