/** * Copy an entire directory tree. * * @param fromDirName from this directory (do nothing if not exist) * @param toDirName to this directory (will create if not exist) * @throws java.io.IOException on io error */ static public void copyDirTree(String fromDirName, String toDirName) throws IOException { File fromDir = new File(fromDirName); File toDir = new File(toDirName); if (!fromDir.exists()) return; if (!toDir.exists()) toDir.mkdirs(); for (File f : fromDir.listFiles()) { if (f.isDirectory()) copyDirTree(f.getAbsolutePath(), toDir.getAbsolutePath() + "/" + f.getName()); else copyFile(f.getAbsolutePath(), toDir.getAbsolutePath() + "/" + f.getName()); } }
/** * Copy an entire directory tree. * * @param fromDirName from this directory (do nothing if not exist) * @param toDirName to this directory (will create if not exist) * @throws java.io.IOException on io error */ static public void copyDirTree(String fromDirName, String toDirName) throws IOException { File fromDir = new File(fromDirName); File toDir = new File(toDirName); if (!fromDir.exists()) return; if (!toDir.exists()) { if (!toDir.mkdirs()) { throw new IOException("Could not create directory: " + toDir); } } File[] files = fromDir.listFiles(); if (files != null) for (File f : files) { if (f.isDirectory()) copyDirTree(f.getAbsolutePath(), toDir.getAbsolutePath() + "/" + f.getName()); else copyFile(f.getAbsolutePath(), toDir.getAbsolutePath() + "/" + f.getName()); } }
/** * Copy an entire directory tree. * * @param fromDirName from this directory (do nothing if not exist) * @param toDirName to this directory (will create if not exist) * @throws java.io.IOException on io error */ static public void copyDirTree(String fromDirName, String toDirName) throws IOException { File fromDir = new File(fromDirName); File toDir = new File(toDirName); if (!fromDir.exists()) return; if (!toDir.exists()) { if (!toDir.mkdirs()) { throw new IOException("Could not create directory: " + toDir); } } File[] files = fromDir.listFiles(); if (files != null) for (File f : files) { if (f.isDirectory()) copyDirTree(f.getAbsolutePath(), toDir.getAbsolutePath() + "/" + f.getName()); else copyFile(f.getAbsolutePath(), toDir.getAbsolutePath() + "/" + f.getName()); } }
IO.copyFile(summaryFileLocation, System.out);
@Test public void testClose() throws IOException { File org = new File(TestDir.cdmLocalTestDataDir + "rankTest.nc"); File copy = tempFolder.newFile(); IO.copyFile(org, copy); String url = copy.getPath(); openDatasetAndView(url); alterExistingFile(url); checkFile(url); }
@Test public void testRedefine() throws IOException, InvalidRangeException { String org = TestDir.cdmLocalTestDataDir + "testWriteRecord.nc"; String path = tempFolder.newFile().getAbsolutePath(); File orgFile = new File(org); File newFile = new File(path); if (newFile.exists()) newFile.delete(); IO.copyFile(orgFile, newFile); try (NetcdfFileWriter ncfile = NetcdfFileWriter.openExisting(path)) { System.out.println(ncfile); ncfile.setRedefineMode(true); Variable tvar = ncfile.findVariable("T"); ncfile.setExtraHeaderBytes(1024); ncfile.addVariable("header_data", DataType.FLOAT, tvar.getDimensions()); System.out.println(ncfile); } } }