FileUtils { public static void saveFile(Resource file, String text, boolean append) throws IOException { if(file.isDirectory()) { throw new IOException(file+": Is a directory"); } try (OutputStream out = file.write(append);) { out.write(text.getBytes()); } }  static void saveFile(Resource file, String text, boolean append);  }
@Test(expected = IOException.class) public void testIOExceptionSaveFile() throws IOException { resource = aeshContext.getCurrentWorkingDirectory().newInstance("."); FileUtils.saveFile(resource, "foo", false); }
@Test public void testSaveFile() throws IOException { File file = File.createTempFile("tmp", ".tmp"); file.delete(); file.mkdir(); file.deleteOnExit(); File child = new File(file, "child.txt"); child.createNewFile(); child.deleteOnExit(); aeshContext.setCurrentWorkingDirectory(new FileResource(file)); resource = aeshContext.getCurrentWorkingDirectory(); FileUtils.saveFile(resource.list().get(0), "foo", false); File f = new File(resource.list().get(0).getAbsolutePath()); Assert.assertEquals(new String(Files.readAllBytes(f.toPath())), "foo"); }