Tabnine Logo
FileNotFoundException
Code IndexAdd Tabnine to your IDE (free)

How to use
FileNotFoundException
in
java.io

Best Java code snippets using java.io.FileNotFoundException (Showing top 20 results out of 37,620)

Refine searchRefine arrow

  • FileInputStream
  • URL
  • FileOutputStream
  • InputStream
  • BufferedReader
  • InputStreamReader
  • FileReader
  • OutputStream
  • URI
origin: redisson/redisson

/**
 * Reads lines from source files.
 */
public static String[] readLines(File file, String encoding) throws IOException {
  if (!file.exists()) {
    throw new FileNotFoundException(MSG_NOT_FOUND + file);
  }
  if (!file.isFile()) {
    throw new IOException(MSG_NOT_A_FILE + file);
  }
  List<String> list = new ArrayList<>();
  InputStream in = null;
  try {
    in = new FileInputStream(file);
    if (encoding.startsWith("UTF")) {
      in = new UnicodeInputStream(in, encoding);
    }
    BufferedReader br = new BufferedReader(new InputStreamReader(in, encoding));
    String strLine;
    while ((strLine = br.readLine()) != null)   {
      list.add(strLine);
    }
  } finally {
    StreamUtil.close(in);
  }
  return list.toArray(new String[list.size()]);
}
origin: stanfordnlp/CoreNLP

public MorfetteFileIterator(String filename) {
 try {
  reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "UTF-8"));
  primeNext();
 } catch (UnsupportedEncodingException e) {
  e.printStackTrace();
 } catch (FileNotFoundException e) {
  e.printStackTrace();
 }
}
origin: redwarp/9-Patch-Resizer

  public static void copyfile(File input, File output) {
    try {
      InputStream in = new FileInputStream(input);
      OutputStream out = new FileOutputStream(output);

      byte[] buf = new byte[1024];
      int len;
      while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
      }
      in.close();
      out.close();
    } catch (FileNotFoundException ex) {
      System.out
          .println(ex.getMessage() + " in the specified directory.");
      System.exit(0);
    } catch (IOException e) {
      System.out.println(e.getMessage());
    }
  }
}
origin: stanfordnlp/CoreNLP

private Set<String> loadMWEs() {
 Set<String> mweSet = Generics.newHashSet();  
 try {
  BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(mweFile), "UTF-8"));
  for (String line; (line = br.readLine()) != null;) {
   mweSet.add(line.trim());
  }
  br.close();
 
 } catch (UnsupportedEncodingException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 } catch (FileNotFoundException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 return mweSet;
}
origin: netty/netty

      FileNotFoundException fnf = new FileNotFoundException(fileName);
      ThrowableUtil.addSuppressedAndClear(fnf, suppressed);
      throw fnf;
    FileNotFoundException fnf = new FileNotFoundException(path);
    ThrowableUtil.addSuppressedAndClear(fnf, suppressed);
    throw fnf;
in = url.openStream();
out = new FileOutputStream(tmpFile);
if (TRY_TO_PATCH_SHADED_ID && PlatformDependent.isOsx() && !packagePrefix.isEmpty()) {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(in.available());
  while ((length = in.read(buffer)) > 0) {
    byteArrayOutputStream.write(buffer, 0, length);
  out.write(bytes);
} else {
  while ((length = in.read(buffer)) > 0) {
    out.write(buffer, 0, length);
out.flush();
origin: spotbugs/spotbugs

@ExpectWarning("RE,RV")
public static void main(String[] args) throws IOException {
  String name = "Mr. Ed";
  name = name.replaceAll(".", "s.");
  System.out.println(name);
  // FIXME:FindBugs only catches this error with name.indexOf(String)
  if (name.indexOf("s") > 0)
    System.out.println("Yay");
  else
    System.out.println("Boo");
  String result;
  try {
    BufferedReader findFiles = new BufferedReader(new FileReader("/mainList.txt"));
    if (findFiles.readLine() != null)
      result = findFiles.readLine();
    findFiles.close();
  } catch (FileNotFoundException e) {
    System.exit(7);
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  }
  LineNumberReader tmp = new LineNumberReader(new FileReader("/mainList.txt"));
  int count = 0;
  while (tmp.readLine() != null)
    count++;
  tmp.close();
}
origin: stagemonitor/stagemonitor

  private static void writeFromJarToTempFile(String path, File temp) throws IOException {
    // Prepare buffer for data copying
    byte[] buffer = new byte[1024];
    int readBytes;

    // Open and check input stream
    InputStream is = SigarNativeBindingLoader.class.getResourceAsStream(path);
    if (is == null) {
      throw new FileNotFoundException("File " + path + " was not found inside JAR.");
    }

    // Open output stream and copy data between source file in JAR and the temporary file
    OutputStream os = new FileOutputStream(temp);
    try {
      while ((readBytes = is.read(buffer)) != -1) {
        os.write(buffer, 0, readBytes);
      }
    } finally {
      // If read/write fails, close streams safely before throwing an exception
      os.close();
      is.close();
    }
  }
}
origin: i2p/i2p.i2p

  throw new FileNotFoundException("File not found: " + file);
long len = file.length();
if (len < BLOCK_LEN + HEADER_LEN + skip)
InputStream in = null;
try {
  in = new FileInputStream(file);
  if (skip > 0)
    DataHelper.skip(in, skip);
  return getComment(buffer);
} finally {
  if (in != null) try { in.close(); } catch (IOException ioe) {}
origin: apache/hbase

/**
 * read the content of znode file, expects a single line.
 */
public static String readMyEphemeralNodeOnDisk() throws IOException {
 String fileName = getMyEphemeralNodeFileName();
 if (fileName == null){
  throw new FileNotFoundException("No filename; set environment variable HBASE_ZNODE_FILE");
 }
 FileReader znodeFile = new FileReader(fileName);
 BufferedReader br = null;
 try {
  br = new BufferedReader(znodeFile);
  String file_content = br.readLine();
  return file_content;
 } finally {
  if (br != null) br.close();
 }
}
origin: iBotPeaches/Apktool

  public static File extractToTmp(String resourcePath, String tmpPrefix, Class clazz) throws BrutException {
    try {
      InputStream in = clazz.getResourceAsStream(resourcePath);
      if (in == null) {
        throw new FileNotFoundException(resourcePath);
      }
      File fileOut = File.createTempFile(tmpPrefix, null);
      fileOut.deleteOnExit();
      OutputStream out = new FileOutputStream(fileOut);
      IOUtils.copy(in, out);
      in.close();
      out.close();
      return fileOut;
    } catch (IOException ex) {
      throw new BrutException("Could not extract resource: " + resourcePath, ex);
    }
  }
}
origin: oracle/opengrok

BufferedReader input = null;
try {
  fin = new FileReader(file);
  input = new BufferedReader(fin);
  String line;
  StringBuilder contents = new StringBuilder();
  String EOL = System.getProperty("line.separator");
  while ((line = input.readLine()) != null) {
    contents.append(line).append(EOL);
} catch (java.io.FileNotFoundException e) {
  LOGGER.log(Level.WARNING, "failed to find file: {0}",
      e.getMessage());
} catch (java.io.IOException e) {
  LOGGER.log(Level.WARNING, "failed to read file: {0}",
  if (input != null) {
    try {
      input.close();
    } catch (Exception e) {
      fin.close();
    } catch (Exception e) {
origin: neo4j/neo4j

if ( source == null )
  throw new FileNotFoundException( "Could not find resource '" + resource + "' to unzip" );
      try ( OutputStream file = new BufferedOutputStream( new FileOutputStream( new File( targetDirectory, entry.getName() ) ) ) )
          file.write( scratch, 0, read );
          toCopy -= read;
  source.close();
origin: nanchen2251/CompressHelper

InputStream inputStream = null;
try {
  inputStream = new FileInputStream(filePath);
  BitmapFactory.decodeStream(inputStream, null, options);
  inputStream.close();
} catch (FileNotFoundException exception) {
  exception.printStackTrace();
} catch (IOException exception) {
  exception.printStackTrace();
  InputStream inputStream = null;
  try {
    inputStream = new FileInputStream(filePath);
    BitmapFactory.decodeStream(inputStream, null, options);
    inputStream.close();
  } catch (IOException exception) {
    exception.printStackTrace();
origin: Javen205/IJPay

if (file.exists()) {
  try {
    in = new FileInputStream(file);
    properties = new Properties();
    properties.load(in);
    loadProperties(properties);
  } catch (FileNotFoundException e) {
    LogUtil.writeErrorLog(e.getMessage(), e);
  } catch (IOException e) {
    LogUtil.writeErrorLog(e.getMessage(), e);
    if (null != in) {
      try {
        in.close();
      } catch (IOException e) {
        LogUtil.writeErrorLog(e.getMessage(), e);
origin: thymeleaf/thymeleaf

public Reader reader() throws IOException {
  final InputStream inputStream = this.servletContext.getResourceAsStream(this.path);
  if (inputStream == null) {
    throw new FileNotFoundException(String.format("ServletContext resource \"%s\" does not exist", this.path));
  }
  if (!StringUtils.isEmptyOrWhitespace(this.characterEncoding)) {
    return new BufferedReader(new InputStreamReader(new BufferedInputStream(inputStream), this.characterEncoding));
  }
  return new BufferedReader(new InputStreamReader(new BufferedInputStream(inputStream)));
}
origin: jaydenxiao2016/AndroidFire

public static File from(Context context, Uri uri) throws IOException {
  InputStream inputStream = context.getContentResolver().openInputStream(uri);
  String fileName = getFileName(context, uri);
  String[] splitName = splitFileName(fileName);
  File tempFile = File.createTempFile(splitName[0], splitName[1]);
  tempFile = rename(tempFile, fileName);
  tempFile.deleteOnExit();
  FileOutputStream out = null;
  try {
    out = new FileOutputStream(tempFile);
  } catch (FileNotFoundException e) {
    e.printStackTrace();
  }
  if (inputStream != null) {
    copy(inputStream, out);
    inputStream.close();
  }
  if (out != null) {
    out.close();
  }
  return tempFile;
}
origin: FudanNLP/fnlp

public SequenceReader(String file,boolean hasTarget, String charsetName) {
  this.hasTarget  = hasTarget;
  try {
    reader = new BufferedReader(new UnicodeReader(
        new FileInputStream(file), charsetName));
  } catch (FileNotFoundException e) {
    e.printStackTrace();
  }
}
origin: apache/nifi

    fis = new FileInputStream(file);
  } catch (final FileNotFoundException fnfe) {
    fis = null;
    if (file.exists()) {
      try {
        fis = new FileInputStream(file);
        filename = baseName + extension;
        break openStream;
  throw new FileNotFoundException("Unable to locate file " + originalFile);
final String serializationName;
try {
  bufferedInStream.mark(4096);
  final InputStream in = filename.endsWith(".gz") ? new GZIPInputStream(bufferedInStream) : bufferedInStream;
  final DataInputStream dis = new DataInputStream(in);
  serializationName = dis.readUTF();
  bufferedInStream.reset();
} catch (final EOFException eof) {
  fis.close();
  return new EmptyRecordReader();
      throw new FileNotFoundException("Cannot create TOC Reader because the file " + tocFile + " does not exist");
      throw new FileNotFoundException("Cannot create TOC Reader because the file " + tocFile + " does not exist");
origin: NLPchina/nlp-lang

public static void Writer(String path, String charEncoding, String content) {
  OutputStream fos = null;
  try {
    fos = new FileOutputStream(new File(path));
    fos.write(content.getBytes(charEncoding));
    fos.flush();
  } catch (FileNotFoundException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  } finally {
    close(fos);
  }
}
origin: spring-projects/spring-framework

/**
 * Resolve the given resource URL to a {@code java.io.File},
 * i.e. to a file in the file system.
 * @param resourceUrl the resource URL to resolve
 * @param description a description of the original resource that
 * the URL was created for (for example, a class path location)
 * @return a corresponding File object
 * @throws FileNotFoundException if the URL cannot be resolved to
 * a file in the file system
 */
public static File getFile(URL resourceUrl, String description) throws FileNotFoundException {
  Assert.notNull(resourceUrl, "Resource URL must not be null");
  if (!URL_PROTOCOL_FILE.equals(resourceUrl.getProtocol())) {
    throw new FileNotFoundException(
        description + " cannot be resolved to absolute file path " +
        "because it does not reside in the file system: " + resourceUrl);
  }
  try {
    return new File(toURI(resourceUrl).getSchemeSpecificPart());
  }
  catch (URISyntaxException ex) {
    // Fallback for URLs that are not valid URIs (should hardly ever happen).
    return new File(resourceUrl.getFile());
  }
}
java.ioFileNotFoundException

Javadoc

Thrown when a file specified by a program cannot be found.

Most used methods

  • <init>
    Constructs a FileNotFoundException with a detail message consisting of the given pathname string fol
  • printStackTrace
  • getMessage
  • toString
  • getLocalizedMessage
  • initCause
  • getCause
  • getStackTrace

Popular in Java

  • Running tasks concurrently on multiple threads
  • addToBackStack (FragmentTransaction)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • notifyDataSetChanged (ArrayAdapter)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • BoxLayout (javax.swing)
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now