/** * Ensure the existence of a given directory. * * @throws IOException if it cannot be created and does not already exist */ private static void ensureDirectory(File dir) throws IOException { if (!dir.mkdirs() && !dir.isDirectory()) { throw new IOException("Mkdirs failed to create " + dir.toString()); } }
public static void main(String[] args) throws Exception { String input1 ="D:/Datasets/sighan2006/processed"; File f = new File(input1); if (f.isDirectory()) { File[] files = f.listFiles(); for (int i = 0; i < files.length; i++) { processLabeledData(files[i].toString(),"utf8","gbk"); } } System.out.println("Done"); }
private File findManifestInSpecifiedPath(String androidManifestPath) throws FileNotFoundException { File androidManifestFile = new File(androidManifestPath); if (!androidManifestFile.exists()) { LOGGER.error("Could not find the AndroidManifest.xml file in specified path : {}", androidManifestPath); throw new FileNotFoundException(); } else { LOGGER.debug("AndroidManifest.xml file found with specified path: {}", androidManifestFile.toString()); } return androidManifestFile; }
@BeforeClass public void setUp() throws Exception { this.eventBus.register(this); // Prepare the test url to download the job conf from final URL url = GobblinAWSClusterLauncherTest.class.getClassLoader().getResource(JOB_FIRST_ZIP); final String jobConfZipUri = getJobConfigZipUri(new File(url.toURI())); // Prepare the test dir to download the job conf to if (this.jobConfigFileDir.exists()) { FileUtils.deleteDirectory(this.jobConfigFileDir); } Assert.assertTrue(this.jobConfigFileDir.mkdirs(), "Failed to create " + this.jobConfigFileDir); final Config config = getConfig(jobConfZipUri) .withValue(GobblinClusterConfigurationKeys.JOB_CONF_PATH_KEY, ConfigValueFactory.fromAnyRef(this.jobConfigFileDir.toString())) .withValue(GobblinAWSConfigurationKeys.JOB_CONF_REFRESH_INTERVAL, ConfigValueFactory.fromAnyRef("10s")); this.jobConfigurationManager = new AWSJobConfigurationManager(this.eventBus, config); this.jobConfigurationManager.startAsync().awaitRunning(); }
URL u = MaybeNo2Dot0Since.class.getResource(MaybeNo2Dot0Since.class.getSimpleName() + ".class"); String path = new File(u.toURI()).toString().replace('\\', '/'); System.out.println("Can't find the base RxJava directory"); return null; File f = new File(p); System.out.println("Can't read " + p); return null;
System.out.println("Processing tileset " + tilesetName); System.out.println("Stripped id #" + gid + " from tileset \"" + tilesetName + "\""); System.out.println("Adding " + tileWidth + "x" + tileHeight + " (" + (int)tileLocation.x + ", " + (int)tileLocation.y + ")"); String tilesetOutputDir = outputDir.toString() + "/" + this.settings.tilesetOutputDirectory; File relativeTilesetOutputDir = new File(tilesetOutputDir); File outputDirTilesets = new File(relativeTilesetOutputDir.getCanonicalPath()); outputDirTilesets.mkdirs(); packer.pack(outputDirTilesets, this.settings.atlasOutputName + ".atlas");
public static synchronized void errorLogging(Throwable e) { String message = "Unknown error.", trace = "Unknown trace.", filename = (new File(Environment.getExternalStorageDirectory().toString(), ERROR_LOG_FILENAME)).getAbsolutePath(); if (e != null) { if (e.getMessage() != null && !e.getMessage().isEmpty()) message = e.getMessage(); else if (e.toString() != null) message = e.toString(); if (message.equals(mLastError)) return; Writer sWriter = new StringWriter(); PrintWriter pWriter = new PrintWriter(sWriter); e.printStackTrace(pWriter); trace = sWriter.toString(); if (mContext != null && getSettings().getBoolean("PREF_DEBUG_ERROR_LOGGING", false)) { try { FileWriter fWriter = new FileWriter(filename, true); BufferedWriter bWriter = new BufferedWriter(fWriter); bWriter.write(trace); bWriter.close(); } catch (IOException ioe) { Logger.error(ioe.toString()); } } } setLastError(message); Logger.error(message); Logger.error(trace); }
// snippet taken from question File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); path = new File(path, "SubDirName"); path.mkdirs(); // initiate media scan and put the new things into the path array to // make the scanner aware of the location and the files you want to see MediaScannerConnection.scanFile(this, new String[] {path.toString()}, null, null);
InputStream in = zipFile.getInputStream(entry); try { File file = new File(unzipDir, entry.getName()); if (!file.getParentFile().mkdirs()) { if (!file.getParentFile().isDirectory()) { throw new IOException("Mkdirs failed to create " + file.getParentFile().toString());
/** * @param segmentDirectory File pointing to segment directory * @param metadata segment metadata. Metadata must be fully initialized * @param readMode mmap vs heap map mode */ protected ColumnIndexDirectory(File segmentDirectory, SegmentMetadataImpl metadata, ReadMode readMode) { Preconditions.checkNotNull(segmentDirectory); Preconditions.checkNotNull(readMode); Preconditions.checkNotNull(metadata); Preconditions.checkArgument(segmentDirectory.exists(), "SegmentDirectory: " + segmentDirectory.toString() + " does not exist"); Preconditions.checkArgument(segmentDirectory.isDirectory(), "SegmentDirectory: " + segmentDirectory.toString() + " is not a directory"); this.segmentDirectory = segmentDirectory; this.metadata = metadata; this.readMode = readMode; }
private static void loadPluginsInDir(File pluginDir, boolean optional) { File[] contentList = pluginDir.listFiles(); if (contentList == null) { return; } for (File file : contentList) { if (file.getName().endsWith(".jar")) { try { URL url = file.toURI().toURL(); if (IO.verifyURL(url)) { loadInitialPlugin(url, true, optional); if (FindBugs.DEBUG) { System.out.println("Found plugin: " + file.toString()); } } } catch (MalformedURLException e) { } } } }
String javaCode = code != null ? code : "public class " + className + " {}"; Path srcDir = new Path(testDir, "src"); File srcDirPath = new File(srcDir.toString()); srcDirPath.mkdirs(); File sourceCodeFile = new File(srcDir.toString(), className + ".java"); BufferedWriter bw = Files.newBufferedWriter(sourceCodeFile.toPath(), StandardCharsets.UTF_8); bw.write(javaCode); srcFileNames.add(sourceCodeFile.toString()); StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); String currentDir = new File(".").getAbsolutePath(); String classpath = currentDir + File.separator + "target"+ File.separator + "classes" + System.getProperty("path.separator") File jarFile = new File(folder, jarFileName); jarFile.getParentFile().mkdirs(); if (!createJarArchive(jarFile, new File[]{new File(srcDir.toString(), className + ".class")})){
private static void createTempDirWithSpecialCharactersInName() throws IOException { if ( !TEMP_DIR_WITH_REP_FILE.exists() ) { if ( TEMP_DIR_WITH_REP_FILE.mkdir() ) { System.out.println( "CREATED: " + TEMP_DIR_WITH_REP_FILE.getCanonicalPath() ); } else { System.out.println( "NOT CREATED: " + TEMP_DIR_WITH_REP_FILE.toString() ); } } }
if (!file.exists()) { throw new FileNotFoundException(file.toString()); path = file.getName(); boolean isDir = file.isDirectory(); if (recursive && file.isDirectory()) { boolean noRelativePath = StringUtil.isEmpty(path); String childRelativePath = (noRelativePath ? StringPool.EMPTY : path) + child.getName(); addToZip(zos, child, childRelativePath, comment, recursive);
public void initLog(File logFilePath) throws IOException { RedwoodConfiguration.empty() .handlers(RedwoodConfiguration.Handlers.chain( RedwoodConfiguration.Handlers.showAllChannels(), RedwoodConfiguration.Handlers.stderr), RedwoodConfiguration.Handlers.file(logFilePath.toString()) ).apply(); // fh.setFormatter(new NewlineLogFormatter()); System.out.println("Starting Ssurgeon log, at "+logFilePath.getAbsolutePath()+" date=" + DateFormat.getDateInstance(DateFormat.FULL).format(new Date())); log.info("Starting Ssurgeon log, date=" + DateFormat.getDateInstance(DateFormat.FULL).format(new Date())); }
/** * @param fileName */ public void read(String fileName) { File f = new File(fileName); if (f.isDirectory()) { File[] files = f.listFiles(); for (int i = 0; i < files.length; i++) { read(files[i].toString()); } } else { try { InputStreamReader read = new InputStreamReader( new FileInputStream(fileName), "utf-8"); BufferedReader bin = new BufferedReader(read); String sent; while ((sent = bin.readLine()) != null) { calc(sent); } } catch (Exception e) { } } }
/** * Deletes any files extracted from the JAR during analysis. */ @Override public void closeAnalyzer() { if (tempFileLocation != null && tempFileLocation.exists()) { LOGGER.debug("Attempting to delete temporary files from `{}`", tempFileLocation.toString()); final boolean success = FileUtils.delete(tempFileLocation); if (!success && tempFileLocation.exists()) { final String[] l = tempFileLocation.list(); if (l != null && l.length > 0) { LOGGER.warn("Failed to delete the JAR Analyzder's temporary files from `{}`, " + "see the log for more details", tempFileLocation.getAbsolutePath()); } } } }