我从临时文件中读取并将其写入永久文件,但某处字符串丢失了所有空格
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { String b, filename; b = null; filename = (textfieldb.getText()); try { // TODO add your handling code here: dispose(); Scanner scan; scan = new Scanner(new File("TempSave.txt")); StringBuilder sb = new StringBuilder(); while (scan.hasNext()) { sb.append(scan.next()); } b = sb.toString(); String c; c = b; FileWriter fw = null; try { fw = new FileWriter(filename + ".txt"); } catch (IOException ex) { Logger.getLogger(hiudsjh.class.getName()).log(Level.SEVERE, null, ex); } PrintWriter pw = new PrintWriter(fw); pw.print(c); pw.close(); System.out.println(c); } catch (FileNotFoundException ex) { Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); } dispose(); hiudsjh x = new hiudsjh(); x.setVisible(true); System.out.println(b); }
没有错误消息只是输出应该是剩余空格的文件
凤凰求蛊
人到中年有点甜
回首忆惘然
心有法竹
相关分类