项目结构
代码:
public class WriterXlsx {
public WriterXlsx(String sfilename, List<RecordNameCode> records, List<Day> recordsDay, Integer fullTime) {
String path = "res/" + sfilename + ".xlsx";
URL resURL = getClass().getClassLoader().getResource(path);
try (InputStream inputStream = resURL.openStream())
{
int lastUsedColumn = createListHead().size();
XSSFWorkbook workBook = new XSSFWorkbook(inputStream);
XSSFSheet sheet = workBook.getSheetAt(0);
drawRecordHead(createListHead(),sheet);
writeContent(2, records,sheet);
createPlanForDay(recordsDay,fullTime,lastUsedColumn,sheet,workBook);
try(FileOutputStream out = new FileOutputStream("C:\\Users\\student3\\"+sfilename+".xlsx"); ) {
workBook.write(out);
out.close(); }
} catch (IOException e) {
e.printStackTrace();
}
程序将写入 SfileName 并从res\
IDE(Intellij IDEA)中的文件读取,但它不能独立工作。我无法通过 .jar 存档启动程序。(可能找不到 res 目录)..
显现:
Manifest-Version: 1.0
Main-Class: workhere.Start
上课开始:
public class Start {
public static void main(String[] args) {
System.out.println("It's working");
new Start().start(countDays);
System.out.println("Work is finished");
}
........