首页 > 编程知识 正文

cab文件损坏(文件系统特定的openfile失败)

时间:2023-05-05 18:00:33 阅读:75559 作者:4308

tillnowmycodeworksfinewhereiamcreatingfileintemporarydirectoryandprocessingit。

butnowiamtryingtoprovidespecificdirectorywhereiactuallywanttocreatexmlfile.soinmethodcreatetmpxmlfile

私有状态参数创建器mpxmlfile (finalstringprefix ) {

try {

log.info (creatingtemporaryfile { } { },prefix,XML_SUFFIX );

return files.create tempfile (paths.get (gleifzipfile ),prefix,XML_SUFFIX );

}catch(ioexceptione ) {

thrownewillegalstateexception (' couldnotcreatetmpfileat ' prefix XML '.',e );

}

}

I changed from

return files.create tempfile (prefix,XML_SUFFIX;

return file.create tempfile (prefix,XML_SUFFIX,'/tmp/in ' );

and I get following error:

Java : incompatible types : Java.lang.stringcannotbeconvertedtojava.io.file。

ifichangethelogicherethenitsaffectingothermethodthatarecallingcreatetmpxmlfilemethod。

I really don ' tunderstandhowtoresolvethisissue.belowismycode :

@Slf4j

publicclassinputcsimplementsrunnable {

publicstaticfinalstringxml _ suffix='.XML ';

@value(($ ) gleifdataimporter.file.dir ) )

私有字符串格雷夫zipfile;

私有语音处理权限文件(

finalatomicbooleanisinsideleirecord=newatomicboolean (;

isinsideleirecord.set(false;

finalstringbuildercurrentleirecordxml=new stringbuilder (;

try (filesystemzipfs=file systems.new file system (job runner.getinputzippath (,null ) ) ) {

pathtmp XML path=xmlfilefromleizipfile (zipfs;

try (streamline s=files.lines (tmp XML path ) ) )

lines.sequential ().foreach (handlelineandincreandincrementlinenumber ) isinsideleirecordxml,currentLeiRecordXml,procesescor

log.info (linesofxmlfileinsideleifinputzipfile ) processed.)、processedLinesCounter.get )、jobrunner.getiitity

}catch(ioexceptione ) {

thrownewillegalstateexception (problemreadinginputfileat ' job runner.getinputzippath ),e );

} finally {

files.delete (tmp XML路径);

}

}catch(ioexceptione ) {

thrownewillegalstateexception (problemreadinginputfileat ' job runner.getinputzippath ),e );

}

}

privatepathxmlfilefromleizipfile (filesystemzipfs )//extractsthexmlfilefromzipfile

log.info(inputfile ) exists: )、jobRunner.getInputZipPath )、files.exists (job runner.getinputzippatath )、和

pathtmp XML path=createtmpxmlfile (' Leif _ _ ' system.current time millis );

path rootdir : zipfs.getrootdirectories () ) ) )。

try (流文件=treeat (rootdir ) ) }

log.info (tryingtoextractleifxmlfilefromzipfileinto )、tmpXmlPath );

finalpathxmlfileinsidezip=files

. filter(isnotadir ) )

. filter (files :3360 isregularfile )。

. findFirst () )

. orElseThrow ()-newillegalstateexception (' nofilefoundinleizipfile.' );

log.info (pathtoleifxmlFileInsideZipfile : { }.',xmlfileinsidezip );

返回复制(xmlfileinsidezip,tmp XML路径);

}

}

thrownewillegalstateexception (' nofilefoundinleizipfile ' job runner.getinputzippath ('.' ) );

}

私有状态参数创建器mpxmlfile (finalstringprefix ) {

try {

log.info (creatingtemporaryfile { } { },prefix,XML_SUFFIX );

return files.create tempfile (paths.get (gleifzipfile ),prefix,XML_SUFFIX );

}catch(ioexceptione ) {

thrownewillegalstateexception (' couldnotcreatetmpfileat ' prefix XML '.',e );

}

}

@NotNull

隐私保护(path from,Path to ) {

请求空值(from,' Trying to copy from a path,which is null to path ' to '.' ); //tryingtocopyfilewherenoxmlfileexistinrootdirectory

请求空值(to,' tryingtocopyfrompath ' from ' to apath,which is null.';

try {

return files.copy (从,到,REPLACE_EXISTING );

}catch(ioexceptione ) {

thrownewillegalstateexception (cannot copy from ' from ' to ' to '.',e );

}

}

}

As suggested by Slaw,usefiles#createtempfile(path,String,String,FileAttribute . ) tospecifythedirectorytocreatetetempppte

usepaths#get(String,String . ) for java 7 or 8,orpath#of ) String,string . (for Java 11 orlatertoconvertstringtopath . )

私有状态参数创建器mpxmlfile (finalstringprefix ) {

try {

//Java 11 or later

//return files.create tempfile (path.of )、prefix、XML_SUFFIX );

//Java 8

return files.create tempfile (paths.get ('/tmp/in ',prefix,XML_SUFFIX );

}catch(ioexceptione ) {

thrownewillegalstateexception (' couldnotcreatetmpfileat ' prefix XML '.',e );

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。