- 当remove 导入的jar包后,在jar文件上右键会没有build path选项
- 直接在项目包文件夹上右键–>配置build path、
- 一个JFrame中加入多个JButton时,最后一个JButton会存在现实异常
- 可以加一个空的JButton,不使用
将double或者float型数值转换为字符串
- float dec = 0.12345f;
//读取文件 DecimalFormat df = new DecimalFormat("#%");//乘以100后以百分比形式输出,此处输出"12%" DecimalFormat df = new DecimalFormat("##.##");//输出"0.12" DecimalFormat df = new DecimalFormat("00.00");//输出"00.12" String s = df.format(dec); System.out.println(s);
- float dec = 0.12345f;
Java读取文件对话框,并读取.xlsx格式文件(输出)
Student student = null; List<String> array = new ArrayList<>(); fd = new FileDialog(f, "Open", FileDialog.LOAD); fd.setVisible(true); try { file1 = new File(fd.getDirectory(), fd.getFile()); InputStream instream = new FileInputStream(file1); xssfWorkbook = new XSSFWorkbook(instream); XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0); for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) { xssfRow = xssfSheet.getRow(rowNum); student = new Student(); xssfRow.getCell(0).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(1).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(2).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(3).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(4).setCellType(Cell.CELL_TYPE_STRING); student.setStudentId(xssfRow.getCell(0).getStringCellValue()); student.setStudentName(xssfRow.getCell(1).getStringCellValue()); student.setStudentPic(xssfRow.getCell(2).getStringCellValue()); student.setCalledNumber(Integer.valueOf(xssfRow.getCell(3).getStringCellValue())); student.setLateNumber(Integer.valueOf(xssfRow.getCell(4).getStringCellValue())); pList.add(student); } instream.close(); flushWindow(pList); } catch (IOException ioe) { ioe.printStackTrace(); }
//输出文件 try { file2 = new File("学期报表.xlsx"); OutputStream outstream = new FileOutputStream(file2); xssfWorkbook = new XSSFWorkbook(); XSSFSheet xssfSheet = xssfWorkbook.createSheet(); XSSFRow xssfRow = xssfSheet.createRow(0); xssfRow.createCell(0).setCellValue("学号"); xssfRow.createCell(1).setCellValue("姓名"); xssfRow.createCell(2).setCellValue("图片地址"); xssfRow.createCell(3).setCellValue("被叫次数"); xssfRow.createCell(4).setCellValue("迟到次数"); xssfRow.createCell(5).setCellValue("总评成绩"); for (int rowNum = 0; rowNum < pList.size(); rowNum++) { xssfRow = xssfSheet.createRow(rowNum + 1); xssfRow.createCell(0).setCellValue(pList.get(rowNum).getStudentId()); xssfRow.createCell(1).setCellValue(pList.get(rowNum).getStudentName()); xssfRow.createCell(2).setCellValue(pList.get(rowNum).getStudentPic()); xssfRow.createCell(3).setCellValue(String.valueOf(pList.get(rowNum).getCalledNumber())); xssfRow.createCell(4).setCellValue(String.valueOf(pList.get(rowNum).getLateNumber())); if (pList.get(rowNum).getCalledNumber() == 0) { xssfRow.createCell(5).setCellValue("0"); } else { double result = (double) pList.get(rowNum).getLateNumber() / pList.get(rowNum).getCalledNumber(); DecimalFormat df = new DecimalFormat("#%");// 乘以100后以百分比形式输出,此处输出"12%" String str = df.format(result); xssfRow.createCell(5).setCellValue(str); } xssfRow.getCell(0).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(1).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(2).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(3).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(4).setCellType(Cell.CELL_TYPE_STRING); xssfRow.getCell(5).setCellType(Cell.CELL_TYPE_STRING); } xssfWorkbook.write(outstream); outstream.flush(); outstream.close(); PublicWindowSet.promptPopUp("输出报表文件成功!!!", "提示", frame); } catch (IOException ioe) { ioe.printStackTrace(); }
项目检出JRE问题(Unbound classpath container: ‘JRE System Library [JavaSE-1.7]’ in project ‘idweb’)
- Uncaught error fetching image
- jdk版本不对应,可能过低
- Operation not allowed after ResultSet closed的问题
- 数据库执行操作未关闭
- java乱码的几个地方修改
- windows - preferences - general - content types
- windows - preferences - general - workspace
- 项目右键 - preferences
- 文件右键 - preferences
- 项目右键 - run configure - common
一周Java开发问题记录
最新推荐文章于 2022-05-10 13:45:48 发布