List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException(String s)
FileNotFoundException
with the specified detail message. From source file:com.filelocker.andy.MainActivity.java
public void lockButton_Click(View view) { TextView vPasswordText = (TextView) findViewById(R.id.passwordText); TextView vFileChooserText = (TextView) findViewById(R.id.fileChooserText); String myPassword = vPasswordText.getText().toString(); vPasswordText.setText(""); if (vFileChooserText.getText().toString().equals("") || myPassword.equals("")) { Toast toast;//from w w w . j a v a 2s. c om if (vFileChooserText.getText().toString().equals("")) { toast = Toast.makeText(getApplicationContext(), "File Not Choosen", Toast.LENGTH_LONG); toast.show(); } else if (myPassword.equals("")) { toast = Toast.makeText(getApplicationContext(), "Password Field Empty", Toast.LENGTH_LONG); toast.show(); } return; } else if (!(vFileChooserText.getText().toString() .substring(vFileChooserText.getText().toString().lastIndexOf('.') + 1).equals("encrypt"))) { AES_Encryption en = new AES_Encryption(myPassword); /* * setup encryption cipher using password. print out iv and salt */ try { File vInFile = new File(vFileChooserText.getText().toString()); if (vInFile.exists() == false) { throw new FileNotFoundException("File Not Found"); } en.setupEncrypt(); } catch (InvalidKeyException ex) { ex.printStackTrace(); } catch (NoSuchAlgorithmException ex) { ex.printStackTrace(); } catch (InvalidKeySpecException ex) { ex.printStackTrace(); } catch (NoSuchPaddingException ex) { ex.printStackTrace(); } catch (InvalidParameterSpecException ex) { ex.printStackTrace(); } catch (IllegalBlockSizeException ex) { ex.printStackTrace(); } catch (BadPaddingException ex) { ex.printStackTrace(); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } /* * write out encrypted file */ try { File vInFile = new File(vFileChooserText.getText().toString()); File vOutFile = new File(vFileChooserText.getText().toString() + ".encrypt"); if (vInFile.exists() == false) { throw new FileNotFoundException("File Not Found"); } en.WriteEncryptedFile(vInFile, vOutFile); Toast toast = Toast.makeText(getApplicationContext(), "Encryption Complete", Toast.LENGTH_LONG); toast.show(); vInFile.delete(); } catch (IllegalBlockSizeException ex) { ex.printStackTrace(); } catch (BadPaddingException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } else { /* * decrypt file */ AES_Encryption dc = new AES_Encryption(myPassword); try { File vInFile = new File(vFileChooserText.getText().toString()); if (vInFile.exists() == false) { throw new FileNotFoundException("File Not Found"); } dc.setupDecrypt(vInFile); } catch (InvalidKeyException ex) { ex.printStackTrace(); } catch (NoSuchAlgorithmException ex) { ex.printStackTrace(); } catch (InvalidKeySpecException ex) { ex.printStackTrace(); } catch (NoSuchPaddingException ex) { ex.printStackTrace(); } catch (InvalidAlgorithmParameterException ex) { ex.printStackTrace(); } catch (DecoderException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } /* * write out decrypted file */ try { File vInFile = new File(vFileChooserText.getText().toString()); File vOutFile = new File(vFileChooserText.getText().toString().substring(0, vFileChooserText.getText().toString().length() - 8)); if (vInFile.exists() == false) { throw new FileNotFoundException("File Not Found"); } dc.ReadEncryptedFile(vInFile, vOutFile); vInFile.delete(); Toast toast = Toast.makeText(getApplicationContext(), "Decryption Complete", Toast.LENGTH_LONG); toast.show(); } catch (IllegalBlockSizeException ex) { ex.printStackTrace(); } catch (BadPaddingException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:edu.cornell.mannlib.vitro.webapp.i18n.VitroResourceBundle.java
private void loadProperties() throws IOException { String resourceName = control.toResourceName(bundleName, "properties"); String defaultsPath = joinPath(appI18nPath, resourceName); String propertiesPath = joinPath(themeI18nPath, resourceName); File defaultsFile = locateFile(defaultsPath); File propertiesFile = locateFile(propertiesPath); if ((defaultsFile == null) && (propertiesFile == null)) { throw new FileNotFoundException( "Property file not found at '" + defaultsPath + "' or '" + propertiesPath + "'"); }/* www . ja v a 2 s .c om*/ if (defaultsFile != null) { log.debug("Loading bundle '" + bundleName + "' defaults from '" + defaultsPath + "'"); FileInputStream stream = new FileInputStream(defaultsFile); Reader reader = new InputStreamReader(stream, "UTF-8"); try { this.defaults.load(reader); } finally { reader.close(); } } if (propertiesFile != null) { log.debug("Loading bundle '" + bundleName + "' overrides from '" + propertiesPath + "'"); FileInputStream stream = new FileInputStream(propertiesFile); Reader reader = new InputStreamReader(stream, "UTF-8"); try { this.properties.load(reader); } finally { reader.close(); } } }
From source file:com.skynetcomputing.skynetserver.persistence.FileManager.java
protected File getTasksFolder(int jobID) throws FileNotFoundException { File file = new File(getJobFolder(jobID) + File.separator + TASK_FOLDER_NAME); if (!file.exists()) { throw new FileNotFoundException(file.getAbsolutePath()); }/*from ww w . j ava 2s.com*/ return file; }
From source file:org.zols.documents.service.DocumentService.java
private void delete(File f) throws IOException { if (f.isDirectory()) { for (File c : f.listFiles()) { delete(c);//from w w w.j a va 2 s . com } } if (!f.delete()) { throw new FileNotFoundException("Failed to delete file: " + f); } }
From source file:eu.esdihumboldt.hale.common.headless.impl.WorkspaceServiceImpl.java
private PropertiesFile getConfiguration(String workspaceId) throws IOException { File configFile = configFile(getWorkspaceFolder(workspaceId)); if (configFile.exists()) { return new PropertiesFile(configFile); }// w ww . j a v a 2 s .com throw new FileNotFoundException("Workspace configuration file missing"); }
From source file:io.cloudine.rhq.plugins.worker.ResourceUtils.java
/** * ? ? ? {@link java.io.File} . ?? . * * @param resourceLocation ? . ? ? "classpath:", "file:" ? ? ? . * @return ?? {@link java.io.File} ?/* w ww . j a va 2s . c o m*/ * @throws java.io.FileNotFoundException ?? ? */ public static File getFile(String resourceLocation) throws FileNotFoundException { if (resourceLocation.startsWith(CLASSPATH_URL_PREFIX)) { String path = resourceLocation.substring(CLASSPATH_URL_PREFIX.length()); String description = "CLASSPATH [" + path + "]"; URL url = getDefaultClassLoader().getResource(path); if (url == null) { throw new FileNotFoundException(description + "? ? . ? ? ? ."); } return getFile(url, description); } try { // URL ? return getFile(new URL(resourceLocation)); } catch (MalformedURLException e) { // no URL -> ? return new File(resourceLocation); } }
From source file:net.pms.dlna.DLNAMediaSubtitle.java
/** * @param externalFile the externalFile to set */// w w w .jav a 2s . co m public void setExternalFile(File externalFile) throws FileNotFoundException { if (externalFile == null) { throw new FileNotFoundException("Can't read file: no file supplied"); } else if (!FileUtil.getFilePermissions(externalFile).isReadable()) { throw new FileNotFoundException("Insufficient permission to read " + externalFile.getAbsolutePath()); } this.externalFile = externalFile; setFileSubsCharacterSet(); }
From source file:edu.ku.brc.specify.tools.FixMetaTags.java
/** * Change the contents of text file in its entirety, overwriting any * existing text.// ww w .ja v a2 s .c o m * * This style of implementation throws all exceptions to the caller. * * @param aFile is an existing file which can be written to. * @throws IllegalArgumentException if param does not comply. * @throws FileNotFoundException if the file does not exist. * @throws IOException if problem encountered during write. */ static public void setContents(File aFile, String aContents) throws FileNotFoundException, IOException { if (aFile == null) { throw new IllegalArgumentException("File should not be null."); } if (!aFile.exists()) { throw new FileNotFoundException("File does not exist: " + aFile); } if (!aFile.isFile()) { throw new IllegalArgumentException("Should not be a directory: " + aFile); } if (!aFile.canWrite()) { throw new IllegalArgumentException("File cannot be written: " + aFile); } //declared here only to make visible to finally clause; generic reference Writer output = null; try { //use buffering //FileWriter always assumes default encoding is OK! output = new BufferedWriter(new FileWriter(aFile)); output.write(aContents); } finally { //flush and close both "output" and its underlying FileWriter if (output != null) output.close(); } }
From source file:com.jaspersoft.jasperserver.war.OlapGetChart.java
/** * Binary streams the specified file to the HTTP response in 1KB chunks * * @param file The file to be streamed./*w w w . j ava 2 s .c om*/ * @param response The HTTP response object. * @param mimeType The mime type of the file, null allowed. * * @throws IOException if there is an I/O problem. * @throws FileNotFoundException if the file is not found. */ public static void sendTempFile(File file, HttpServletResponse response, String mimeType) throws IOException, FileNotFoundException { if (file.exists()) { BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); // Set HTTP headers if (mimeType != null) { response.setHeader("Content-Type", mimeType); } response.setHeader("Content-Length", String.valueOf(file.length())); SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z"); response.setHeader("Last-Modified", sdf.format(new Date(file.lastModified()))); BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream()); byte[] input = new byte[1024]; boolean eof = false; while (!eof) { int length = bis.read(input); if (length == -1) { eof = true; } else { bos.write(input, 0, length); } } bos.flush(); bis.close(); bos.close(); } else { throw new FileNotFoundException(file.getAbsolutePath()); } return; }
From source file:com.dhenton9000.java.mongo.MongoTest.java
private File convertClassPathToFileRef(String path) throws FileNotFoundException { if (this.getClass().getResource(path) != null) { return new File(FileUtils.toFile(getClass().getResource(path)).getAbsolutePath()); } else {//from ww w. j av a2 s .c o m String info = String.format("unable to find file at '%s'", path); throw new FileNotFoundException(info); } }