List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException(String s)
FileNotFoundException
with the specified detail message. From source file:edu.usf.cutr.onebusaway.nav.utils.CommandLineUtils.java
private static String getInputPath(CommandLine cmd) throws FileNotFoundException { String filePath;/*from w ww.j a va 2 s . c om*/ if (cmd.hasOption("i")) { filePath = cmd.getOptionValue("i"); } else { throw new FileNotFoundException("CSV file path not provided"); } return filePath; }
From source file:Main.java
public static InputStream createWallpaperInputStream(Context context, String preferenceValue) throws FileNotFoundException { File file = new File(preferenceValue); if (file.exists()) { return new FileInputStream(file); }//from ww w.j a v a 2 s .co m Uri uri = Uri.parse(preferenceValue); ContentResolver contentResolver = context.getContentResolver(); try { return contentResolver.openInputStream(uri); } catch (SecurityException e) { Log.i("ThemingUtils", "unable to open background image", e); FileNotFoundException fileNotFoundException = new FileNotFoundException(e.getMessage()); fileNotFoundException.initCause(e); throw fileNotFoundException; } }
From source file:com.sarm.lonelyplanet.process.LPUnMarshallerTest.java
@BeforeClass public static void setUpClass() { Properties prop = new Properties(); logger.info("LPUnMarshallerTest : Commencing loading test properties ..."); String propFileName = LonelyConstants.testPropertyFile; try (InputStream input = new FileInputStream(propFileName)) { if (input == null) { logger.debug("input Stream for test.properties file : is Null "); throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath"); }/*from ww w.j a va 2s . c o m*/ prop.load(input); } catch (FileNotFoundException ex) { logger.debug("FileNotFoundException "); ex.printStackTrace(); } catch (IOException ex) { logger.debug(" IOException"); ex.printStackTrace(); } taxonomyFileName = prop.getProperty(LonelyConstants.propertyTaxonomy); targetLocation = prop.getProperty(LonelyConstants.propertyHtmlTarget); destinationFileName = prop.getProperty(LonelyConstants.propertyDestination); lp = new LPUnMarshaller(taxonomyFileName, destinationFileName, targetLocation, null); }
From source file:de.cosmocode.palava.core.AsciiArt.java
private static InputStream open() throws IOException { final File file = new File("lib", FILE_NAME); final URL resource = AsciiArt.class.getClassLoader().getResource(FILE_NAME); if (file.exists()) { return new FileInputStream(file); } else {//from w ww . j ava 2s .co m if (resource == null) { throw new FileNotFoundException(String.format("classpath:%s", FILE_NAME)); } return resource.openStream(); } }
From source file:net.firejack.platform.core.utils.MiscUtils.java
/** * @param properties/*from w w w . j av a 2 s .c o m*/ * @param checkFileExists * @param property * @param value * @throws java.io.IOException */ public static void setProperties(File properties, boolean checkFileExists, String property, String value) throws IOException { if (checkFileExists && !properties.exists()) { logger.error("Properties file [" + properties.getAbsolutePath() + "] does not exist."); throw new FileNotFoundException("Properties file does not found."); // IOHelper.delete(dbProperties); } Properties props = new Properties(); if (properties.exists()) { FileReader reader = new FileReader(properties); props.load(reader); reader.close(); } props.put(property, value); FileWriter writer = new FileWriter(properties); props.store(writer, null); writer.flush(); writer.close(); }
From source file:com.github.restdriver.serverdriver.file.FileHelper.java
/** * Reads in a resource from the class path. * /* w w w . j a v a 2 s.com*/ * @param fileName The file name to load * @param encoding The encoding to use when reading the file * @return The content of the file */ public static String fromFile(String fileName, String encoding) { InputStream stream = FileHelper.class.getClassLoader().getResourceAsStream(fileName); if (stream == null) { throw new RuntimeFileNotFoundException(new FileNotFoundException(fileName)); } try { return IOUtils.toString(stream, encoding); } catch (IOException e) { throw new RuntimeException("Failed to read from file " + fileName, e); } }
From source file:com.stealthyone.mcb.stbukkitlib.utils.FileUtils.java
public static File copyFileFromJar(JavaPlugin plugin, String fileName, File destination) throws IOException { Validate.notNull(plugin, "Plugin cannot be null."); Validate.notNull(fileName, "File name cannot be null."); Validate.notNull(destination, "Destination cannot be null."); InputStream in = plugin.getResource(fileName); if (in == null) throw new FileNotFoundException( "Unable to find file '" + fileName + "' in jar for plugin: '" + plugin.getName() + "'"); OutputStream out = new FileOutputStream(destination); byte[] buf = new byte[1024]; int len;// w ww .ja va2 s . co m while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.close(); in.close(); return destination; }
From source file:org.apache.kylin.jdbc.TestUtil.java
public static String getResourceContent(String path) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); StringWriter writer = new StringWriter(); InputStream is = loader.getResourceAsStream(path); if (is == null) { throw new IllegalArgumentException(new FileNotFoundException(path + " not found in class path")); }/*from w w w. j a v a 2s . com*/ try { IOUtils.copy(is, writer, "utf-8"); return writer.toString(); } catch (IOException e) { IOUtils.closeQuietly(is); throw new RuntimeException(e); } }
From source file:net.fabricmc.installer.installer.MultiMCInstaller.java
public static void install(File mcDir, String version, IInstallerProgress progress) throws Exception { File instancesDir = new File(mcDir, "instances"); if (!instancesDir.exists()) { throw new FileNotFoundException(Translator.getString("install.multimc.notFound")); }/*from ww w. j av a 2 s. co m*/ progress.updateProgress(Translator.getString("install.multimc.findInstances"), 10); String mcVer = version.split("-")[0]; List<File> validInstances = new ArrayList<>(); for (File instanceDir : instancesDir.listFiles()) { if (instanceDir.isDirectory()) { if (isValidInstance(instanceDir, mcVer)) { validInstances.add(instanceDir); } } } if (validInstances.isEmpty()) { throw new Exception(Translator.getString("install.multimc.noInstances").replace("[MCVER]", mcVer)); } List<String> instanceNames = new ArrayList<>(); for (File instance : validInstances) { instanceNames.add(instance.getName()); } String instanceName = (String) JOptionPane.showInputDialog(null, Translator.getString("install.multimc.selectInstance"), Translator.getString("install.multimc.selectInstance"), JOptionPane.QUESTION_MESSAGE, null, instanceNames.toArray(), instanceNames.get(0)); if (instanceName == null) { progress.updateProgress(Translator.getString("install.multimc.canceled"), 100); return; } progress.updateProgress( Translator.getString("install.multimc.installingInto").replace("[NAME]", instanceName), 25); File instnaceDir = null; for (File instance : validInstances) { if (instance.getName().equals(instanceName)) { instnaceDir = instance; } } if (instnaceDir == null) { throw new FileNotFoundException("Could not find " + instanceName); } File patchesDir = new File(instnaceDir, "patches"); if (!patchesDir.exists()) { patchesDir.mkdir(); } File fabricJar = new File(patchesDir, "Fabric-" + version + ".jar"); if (!fabricJar.exists()) { progress.updateProgress(Translator.getString("install.client.downloadFabric"), 30); FileUtils.copyURLToFile(new URL("http://maven.modmuss50.me/net/fabricmc/fabric-base/" + version + "/fabric-base-" + version + ".jar"), fabricJar); } progress.updateProgress(Translator.getString("install.multimc.createJson"), 70); File fabricJson = new File(patchesDir, "fabric.json"); if (fabricJson.exists()) { fabricJson.delete(); } String json = readBaseJson(); json = json.replaceAll("%VERSION%", version); ZipFile fabricZip = new ZipFile(fabricJar); ZipEntry dependenciesEntry = fabricZip.getEntry("dependencies.json"); String fabricDeps = IOUtils.toString(fabricZip.getInputStream(dependenciesEntry), Charset.defaultCharset()); json = json.replace("%DEPS%", stripDepsJson(fabricDeps.replace("\n", ""))); FileUtils.writeStringToFile(fabricJson, json, Charset.defaultCharset()); fabricZip.close(); progress.updateProgress(Translator.getString("install.success"), 100); }
From source file:net.orpiske.dcd.collector.vocabulary.impl.DictionaryConfigurationWrapper.java
/** * Initializes the configuration object/* www.j av a 2 s.co m*/ * * @param configDir * The configuration directory containing the configuration file * @param fileName * The name of the configuration file * @throws java.io.FileNotFoundException * @throws org.apache.commons.configuration.ConfigurationException */ public static void initConfiguration(final String configDir, final String fileName) throws FileNotFoundException, ConfigurationException { if (configDir == null) { throw new FileNotFoundException("The configuration dir was not found"); } config = new PropertiesConfiguration(configDir + File.separator + fileName); }