Java FileUtils.writeByteArrayToFile在coldfusion中使用
我正在将一些java代码转换为ColdFusion。除此之外,我已经了解了大部分内容:Java FileUtils.writeByteArrayToFile在coldfusion中使用,java,coldfusion,coldfusion-10,lucee,Java,Coldfusion,Coldfusion 10,Lucee,我正在将一些java代码转换为ColdFusion。除此之外,我已经了解了大部分内容: String passKey = "D:\\tmp\\passbook\\key\\pass.p12"; String password = ""; String appleFile = "D:\\tmp\\passbook\\key\\AppleWWDRCA.pem"; String pathToTemplateDirectory = "D:/tmp/passbook/t"; PKSigningInform
String passKey = "D:\\tmp\\passbook\\key\\pass.p12";
String password = "";
String appleFile = "D:\\tmp\\passbook\\key\\AppleWWDRCA.pem";
String pathToTemplateDirectory = "D:/tmp/passbook/t";
PKSigningInformation pkSigningInformation =
PKSigningUtil.loadSigningInformationFromPKCS12FileAndIntermediateCertificateFile(passKey, password, appleFile);
byte[] passZipAsByteArray = PKSigningUtil.createSignedAndZippedPkPassArchive(pass, pathToTemplateDirectory, pkSigningInformation);
FileUtils.forceDelete(new File("D:\\workspace\\emms_maven\\src\\main\\webapp\\WEB-INF\\passbook\\new.pkpass"));
FileUtils.writeByteArrayToFile(new File("D:\\workspace\\emms_maven\\src\\main\\webapp\\WEB-INF\\passbook\\new.pkpass"),
passZipAsByteArray);
在这些线路上我被卡住了。基本上,我正在寻找ColdFusion中的forceDelete
&writeByteArrayToFile
的等价物。有什么想法吗
FileUtils.forceDelete(new File("D:\\workspace\\emms_maven\\src\\main\\webapp\\WEB-INF\\passbook\\new.pkpass"));
FileUtils.writeByteArrayToFile(new File("D:\\workspace\\emms_maven\\src\\main\\webapp\\WEB-INF\\passbook\\new.pkpass"),
passZipAsByteArray);
这两行只是删除一个文件,然后将二进制文件写入同一个文件。因为CF有删除和写入文件的功能,所以我只使用了它的常规文件功能:
<cfset passZipAsByteArray = {}>
<cfset passZipAsByteArray = PKSigningUtil.createSignedAndZippedPkPassArchive(
pass, pathToTemplateDirectory,
pkSigningInformation) />
<cffile action="write"
file="#pathToTemplateDirectory#/#createUUID()#.pkpass"
output="#passZipAsByteArray#">
A)如果您能解释您遇到困难的部位以及原因,对其他人会更有帮助?B) 从小步开始。每次转换一行代码。@Ageax刚刚更新了我的问题主页,我可以清除我的问题。(编辑)翻译代码时,我通常会试图弄清楚代码实际上在做什么,然后决定是否有更好的方法用CF编写。这两行只是删除一个文件,然后将二进制文件写入文件。由于CF具有删除和写入文件的功能,我猜您根本不需要翻译它。只需使用常规文件功能:FileDelete和FileWriteGlad,这很有帮助!谢谢你发布最终答案。很好地抓住了forceDelete!您只需要cffile action=write
或FileWrite()
,因为它将覆盖任何现有文件。希望您不介意,我提交了一个编辑,描述了您为帮助他人所做的一切,非常感谢@Ageax的帮助。。如果它能帮助别人,我会更高兴的。