Tabnine Logo
FileInputStream.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
java.io.FileInputStream
constructor

Best Java code snippets using java.io.FileInputStream.<init> (Showing top 20 results out of 115,641)

Refine searchRefine arrow

  • File.<init>
  • FileOutputStream.<init>
  • PrintStream.println
  • InputStreamReader.<init>
  • BufferedReader.<init>
  • FileInputStream.close
  • File.exists
  • BufferedReader.readLine
  • FileInputStream.read
canonical example by Tabnine

public void copyFile(File srcFile, File dstFile) throws IOException {
 try (FileInputStream fis = new FileInputStream(srcFile);
   FileOutputStream fos = new FileOutputStream(dstFile)) {
  int len;
  byte[] buffer = new byte[1024];
  while ((len = fis.read(buffer)) > 0) {
   fos.write(buffer, 0, len);
  }
 }
}
canonical example by Tabnine

public void zipFile(File srcFile, File zipFile) throws IOException {
 try (FileInputStream fis = new FileInputStream(srcFile);
   ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile))) {
  zos.putNextEntry(new ZipEntry(srcFile.getName()));
  int len;
  byte[] buffer = new byte[1024];
  while ((len = fis.read(buffer)) > 0) {
   zos.write(buffer, 0, len);
  }
  zos.closeEntry();
 }
}
origin: stackoverflow.com

 FileInputStream inputStream = new FileInputStream("foo.txt");
try {
  String everything = IOUtils.toString(inputStream);
} finally {
  inputStream.close();
}
origin: google/guava

/**
 * Returns a buffered reader that reads from a file using the given character set.
 *
 * <p><b>{@link java.nio.file.Path} equivalent:</b> {@link
 * java.nio.file.Files#newBufferedReader(java.nio.file.Path, Charset)}.
 *
 * @param file the file to read from
 * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for
 *     helpful predefined constants
 * @return the buffered reader
 */
public static BufferedReader newReader(File file, Charset charset) throws FileNotFoundException {
 checkNotNull(file);
 checkNotNull(charset);
 return new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
}
origin: stackoverflow.com

 try (
  InputStream in = new FileInputStream(src);
  OutputStream out = new FileOutputStream(dest))
{
 // code
}
origin: stackoverflow.com

 String line;
try (
  InputStream fis = new FileInputStream("the_file_name");
  InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8"));
  BufferedReader br = new BufferedReader(isr);
) {
  while ((line = br.readLine()) != null) {
    // Deal with the line
  }
}
origin: apache/zookeeper

public void chop() {
  File targetFile = new File(txnLogFile.getParentFile(), txnLogFile.getName() + ".chopped" + zxid);
  try (
      InputStream is = new BufferedInputStream(new FileInputStream(txnLogFile));
      OutputStream os = new BufferedOutputStream(new FileOutputStream(targetFile))
  ) {
    if (!LogChopper.chop(is, os, zxid)) {
      throw new TxnLogToolkitException(ExitCode.INVALID_INVOCATION.getValue(), "Failed to chop %s", txnLogFile.getName());
    }
  } catch (Exception e) {
    System.out.println("Got exception: " + e.getMessage());
  }
}
origin: plutext/docx4j

  public static void main(String[] args) throws Exception {
    File file = new File(args[0]);
    InputStream in = new BufferedInputStream(new FileInputStream(file));
    byte[] b = new byte[(int)file.length()];
    in.read(b);
    System.out.println(HexDump.dump(b, 0, 0));
    in.close();
  }
}
origin: alibaba/druid

  private InputStream getFileAsStream(String filePath) throws FileNotFoundException {
    InputStream inStream = null;
    File file = new File(filePath);
    if (file.exists()) {
      inStream = new FileInputStream(file);
    } else {
      inStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
    }
    return inStream;
  }
}
origin: stackoverflow.com

 FileInputStream fis = new FileInputStream(new File("foo"));
String md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis);
fis.close()
origin: stackoverflow.com

 String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
String fileName = "myFile.txt";

// Not sure if the / is on the path or not
File f = new File(baseDir + File.Separator + fileName);
FileInputStream fiStream = new FileInputStream(f);

byte[] bytes;

// You might not get the whole file, lookup File I/O examples for Java
fiStream.read(bytes); 
fiStream.close();
origin: redisson/redisson

/**
 * Decompress gzip archive.
 */
public static File ungzip(File file) throws IOException {
  String outFileName = FileNameUtil.removeExtension(file.getAbsolutePath());
  File out = new File(outFileName);
  out.createNewFile();
  FileOutputStream fos = new FileOutputStream(out);
  GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(file));
  try {
    StreamUtil.copy(gzis, fos);
  } finally {
    StreamUtil.close(fos);
    StreamUtil.close(gzis);
  }
  return out;
}
origin: osmandapp/Osmand

@Override
public byte[] getBytes(int x, int y, int zoom, String dirWithTiles) throws IOException {
  File f = new File(dirWithTiles, calculateTileId(x, y, zoom));
  if (!f.exists())
    return null;
  
  ByteArrayOutputStream bous = new ByteArrayOutputStream();
  FileInputStream fis = new FileInputStream(f);
  Algorithms.streamCopy(fis, bous);
  fis.close();
  bous.close();
  return bous.toByteArray();
}

origin: netty/netty

/**
 * Parse a hosts file.
 *
 * @param file the file to be parsed
 * @param charsets the {@link Charset}s to try as file encodings when parsing.
 * @return a {@link HostsFileEntries}
 * @throws IOException file could not be read
 */
public static HostsFileEntries parse(File file, Charset... charsets) throws IOException {
  checkNotNull(file, "file");
  checkNotNull(charsets, "charsets");
  if (file.exists() && file.isFile()) {
    for (Charset charset: charsets) {
      HostsFileEntries entries = parse(new BufferedReader(new InputStreamReader(
          new FileInputStream(file), charset)));
      if (entries != HostsFileEntries.EMPTY) {
        return entries;
      }
    }
  }
  return HostsFileEntries.EMPTY;
}
origin: deathmarine/Luyten

private void doSaveUnknownFile(File inFile, File outFile) throws Exception {
  try (FileInputStream in = new FileInputStream(inFile); FileOutputStream out = new FileOutputStream(outFile);) {
    System.out.println("[SaveAll]: " + inFile.getName() + " -> " + outFile.getName());
    byte data[] = new byte[1024];
    int count;
    while ((count = in.read(data, 0, 1024)) != -1) {
      out.write(data, 0, count);
    }
  }
}
origin: stackoverflow.com

 FileInputStream fis = new FileInputStream("awesomefile.csv"); 
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
CSVReader reader = new CSVReader(isr);

for (String[] row; (row = reader.readNext()) != null;) {
  System.out.println(Arrays.toString(row));
}

reader.close();
isr.close();
fis.close();
origin: apache/incubator-shardingsphere

private static YamlOrchestrationMasterSlaveRuleConfiguration unmarshal(final File yamlFile) throws IOException {
  try (
      FileInputStream fileInputStream = new FileInputStream(yamlFile);
      InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8")
  ) {
    return new Yaml(new Constructor(YamlOrchestrationMasterSlaveRuleConfiguration.class)).loadAs(inputStreamReader, YamlOrchestrationMasterSlaveRuleConfiguration.class);
  }
}

origin: stackoverflow.com

 public static void copyFile( File from, File to ) throws IOException {

  if ( !to.exists() ) { to.createNewFile(); }

  try (
    FileChannel in = new FileInputStream( from ).getChannel();
    FileChannel out = new FileOutputStream( to ).getChannel() ) {

    out.transferFrom( in, 0, in.size() );
  }
}
origin: stanfordnlp/CoreNLP

public TraditionalSimplifiedCharacterMap(String path) {
 // TODO: gzipped maps might be faster
 try {
  FileInputStream fis = new FileInputStream(path);
  InputStreamReader isr = new InputStreamReader(fis, "utf-8");
  BufferedReader br = new BufferedReader(isr);
  init(br);
  br.close();
  isr.close();
  fis.close();
 } catch (IOException e) {
  throw new RuntimeIOException(e);
 }
}
origin: stackoverflow.com

 private void loadImageFromStorage(String path)
{

  try {
    File f=new File(path, "profile.jpg");
    Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
      ImageView img=(ImageView)findViewById(R.id.imgPicker);
    img.setImageBitmap(b);
  } 
  catch (FileNotFoundException e) 
  {
    e.printStackTrace();
  }

}
java.ioFileInputStream<init>

Javadoc

Constructs a new FileInputStream that reads from file.

Popular methods of FileInputStream

  • close
    Closes this file input stream and releases any system resources associated with the stream. If this
  • read
    Reads up to len bytes of data from this input stream into an array of bytes. If len is not zero, th
  • getChannel
    Returns a read-only FileChannel that shares its position with this stream.
  • available
    Returns an estimate of the number of remaining bytes that can be read (or skipped over) from this in
  • skip
    Skips over and discards n bytes of data from the input stream.The skip method may, for a variety of
  • getFD
    Returns the FileDescriptor object that represents the connection to the actual file in the file syst
  • mark
  • markSupported
  • reset
  • finalize
    Ensures that the close method of this file input stream is called when there are no more references
  • close0
  • isRunningFinalize
  • close0,
  • isRunningFinalize,
  • open,
  • readBytes,
  • transferTo

Popular in Java

  • Running tasks concurrently on multiple threads
  • getContentResolver (Context)
  • getSystemService (Context)
  • runOnUiThread (Activity)
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • Best IntelliJ plugins
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