URL resource = this.getClass().getResource("/ModelDataFiles/" + adcd.substring(0, 6)); String basePath = resource.getPath().substring(1)+ "/";
File file = new File(f4);
FileWriter fileWritter = new FileWriter(file); fileWritter.write(finalStr); fileWritter.close();
字符流存在换行符丢失问题,需手动加换行或用字节流
if (file.exists()) { FileInputStream fileInputStream = null; String initstate = null; try { fileInputStream = new FileInputStream(file); byte[] b = new byte[fileInputStream.available()]; fileInputStream.read(b); fileInputStream.close(); initstate = new String(b); } catch (IOException e) { e.printStackTrace(); } finally { if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException e1) { e1.printStackTrace(); } } }