List of usage examples for java.io FileInputStream FileInputStream
public FileInputStream(FileDescriptor fdObj)
FileInputStream
by using the file descriptor fdObj
, which represents an existing connection to an actual file in the file system. From source file:Main.java
public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(new FileInputStream("c:/text.txt"), StandardCharsets.UTF_8.name()); System.out.println(scanner.nextLine()); scanner.close();//from ww w .j ava 2s. c o m }
From source file:Main.java
public static void main(String[] args) throws Exception { FileInputStream fin = new FileInputStream("a.gz"); GZIPInputStream gzin = new GZIPInputStream(fin); FileOutputStream fout = new FileOutputStream("a.dat"); for (int c = gzin.read(); c != -1; c = gzin.read()) { fout.write(c);/* www .ja v a2s. c o m*/ } fout.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("C:/String.txt"); FileInputStream fin = new FileInputStream(file); int ch;// w w w .j a v a2 s .c o m // skip first 10 bytes fin.skip(10); while ((ch = fin.read()) != -1) { System.out.print((char) ch); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileInputStream is = new FileInputStream("yourfile" + ".keystore"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); String password = "my-keystore-password"; keystore.load(is, password.toCharArray()); Enumeration e = keystore.aliases(); for (; e.hasMoreElements();) { String alias = (String) e.nextElement(); boolean b = keystore.isKeyEntry(alias); b = keystore.isCertificateEntry(alias); }//from w w w. j a va 2 s . c om is.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream("C:/test.txt"); LineNumberInputStream lnis = new LineNumberInputStream(fis); lnis.setLineNumber(100);//from www . j a v a2 s. co m int i = lnis.getLineNumber(); System.out.print("Line number: " + i); }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream inStream = new FileInputStream("c:/test.txt"); BufferedInputStream bis = new BufferedInputStream(inStream); // read until a single byte is available while (bis.available() > 0) { // read the byte and convert the integer to character char c = (char) bis.read(); System.out.println(c);// w w w .ja v a 2 s .co m } }
From source file:Main.java
public static void main(String[] args) throws Exception { FileInputStream fis = new FileInputStream("C:/MyZip.zip"); ZipInputStream zis = new ZipInputStream(fis); ZipEntry ze;/* w w w . j av a 2 s . com*/ while ((ze = zis.getNextEntry()) != null) { System.out.println(ze.getName()); zis.closeEntry(); } zis.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileChannel sourceChannel = new FileInputStream("sourceFile").getChannel(); FileChannel sinkChannel = new FileOutputStream("newFile").getChannel(); // Copy source file contents to the sink file sourceChannel.transferTo(0, sourceChannel.size(), sinkChannel); }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream is = new FileInputStream("C:/test.txt"); // input stream is converted to buffered input stream BufferedInputStream bis = new BufferedInputStream(is); // read until a single byte is available while (bis.available() > 0) { // skip single byte from the stream bis.skip(1);/*from w w w . j a v a 2 s. c o m*/ // read next available byte and convert to char char c = (char) bis.read(); System.out.print(c); } }
From source file:Main.java
public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream("C:/test.txt"); InputStreamReader isr = new InputStreamReader(fis); // input stream reader is closed isr.close();/* w w w. ja v a 2 s . co m*/ System.out.print("close() invoked"); // read() called after closed method int i = isr.read(); char c = (char) i; System.out.println(c); }