第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

寫入帶有子文件夾的新文件時(shí)自動(dòng)創(chuàng)建整個(gè)路徑

寫入帶有子文件夾的新文件時(shí)自動(dòng)創(chuàng)建整個(gè)路徑

胡說叔叔 2021-06-21 19:15:33
我想在當(dāng)前不存在的文件夾中寫入一個(gè)新文件。我像這樣使用它:File file = new File("C:\\user\\Desktop\\dir1\\dir2\\filename.txt");file.getParentFile().mkdirs();FileWriter writer = new FileWriter(file);我filename.txt在一個(gè)名為dir1.dir2.我需要dir1/dir2:我怎樣才能做到這一點(diǎn)?請(qǐng)不要將此問題標(biāo)記為重復(fù),因?yàn)槲以谘芯亢鬀]有得到我需要的東西。更新 1我正在使用帶有 Spring Boot 的 Jasper Report 導(dǎo)出 pdf 文件。我需要在目錄名稱下創(chuàng)建文件current year. 在這個(gè)文件夾下,我需要?jiǎng)?chuàng)建一個(gè)名為 的目錄the current month,在這個(gè)目錄下應(yīng)該導(dǎo)出pdf文件。例子 :(2018/auguest/report.pdf)我LocalDateTime用來獲取 year和month這是我的代碼的一部分:    ReportFiller reportFiller = context.getBean(ReportFiller.class);    reportFiller.setReportFileName("quai.jrxml");    reportFiller.compileReport();    reportFiller = context.getBean(ReportFiller.class);    reportFiller.fillReport();    ReportExporter simpleExporter = context.getBean(ReportExporter.class);    simpleExporter.setJasperPrint(reportFiller.getJasperPrint());    LocalDateTime localDateTime = LocalDateTime.now();    String dirName = simpleExporter.getPathToSaveFile() + "/"+     localDateTime.getYear() + "/" + localDateTime.getMonth().name();    File dir = new File(dirName);    dir.mkdirs();    String fileName = dirName + "/quaiReport.pdf";    simpleExporter.exportToPdf(fileName, "");這是我得到的:
查看完整描述

3 回答

?
拉丁的傳說

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊

嘗試下面的代碼,它將按照您的期望工作


File dir = new File("C:\\Users\\username\\Desktop\\dir1\\dir2");

dir.mkdirs();

File file = new File(dir, "filename.txt");

FileWriter newFile = new FileWriter(file);

您需要先創(chuàng)建文件夾結(jié)構(gòu),然后再創(chuàng)建文件


查看完整回答
反對(duì) 回復(fù) 2021-06-23
  • 3 回答
  • 0 關(guān)注
  • 206 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)