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:MainClass.java
public static void main(String[] a) { File aFile = new File("C:/myFile.text"); FileInputStream inputFile1 = null; FileDescriptor fd = null;//w ww .ja v a2 s . c om try { inputFile1 = new FileInputStream(aFile); fd = inputFile1.getFD(); } catch (IOException e) { e.printStackTrace(System.err); System.exit(1); } FileInputStream inputFile2 = new FileInputStream(fd); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { File fromFile = new File("fromFile.txt"); File toFile = new File("toFile.txt"); FileInputStream inFile = new FileInputStream(fromFile); FileOutputStream outFile = new FileOutputStream(toFile); FileChannel inChannel = inFile.getChannel(); FileChannel outChannel = outFile.getChannel(); int bytesWritten = 0; long byteCount = inChannel.size(); while (bytesWritten < byteCount) { bytesWritten += inChannel.transferTo(bytesWritten, byteCount - bytesWritten, outChannel); }//from ww w .java2 s.c om inFile.close(); outFile.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { XPath xp = XPathFactory.newInstance().newXPath(); InputSource xml = new InputSource(new FileInputStream("input.xml")); double count = (Double) xp.evaluate("count(//slot[@name='slot1']/port)", xml, XPathConstants.NUMBER); }
From source file:MainClass.java
public static void main(String[] args) throws IOException { for (int i = 0; i < args.length; i++) { FileInputStream fin = new FileInputStream(args[i]); ZipInputStream zin = new ZipInputStream(fin); ZipEntry ze = null;//from w w w .j a v a2 s.co m while ((ze = zin.getNextEntry()) != null) { System.out.println("Unzipping " + ze.getName()); FileOutputStream fout = new FileOutputStream(ze.getName()); for (int c = zin.read(); c != -1; c = zin.read()) { fout.write(c); } zin.closeEntry(); fout.close(); } zin.close(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileInputStream is = new FileInputStream("your.keystore"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(is, "my-keystore-password".toCharArray()); String alias = "myalias"; Key key = keystore.getKey(alias, "password".toCharArray()); if (key instanceof PrivateKey) { // Get certificate of public key Certificate cert = keystore.getCertificate(alias); // Get public key PublicKey publicKey = cert.getPublicKey(); // Return a key pair new KeyPair(publicKey, (PrivateKey) key); }/* w ww .ja v a2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { try {//from www . java2 s. c om OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os); // create a new FileInputStream to read what we write FileInputStream in = new FileInputStream("test.txt"); // write something in the file writer.write(70); // flush the stream writer.flush(); // read what we write System.out.println((char) in.read()); // close the stream writer.close(); os.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream inputStream = new FileInputStream("data.xml"); InputSource inputSource = new InputSource(inputStream); XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile("/PaymentElement/Payment/@seqID"); Object result = expr.evaluate(inputSource, XPathConstants.STRING); System.out.println(result);/* ww w. j a va 2 s .c o m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { String fromFileName = "from.txt"; String toFileName = "to.txt"; BufferedInputStream in = new BufferedInputStream(new FileInputStream(fromFileName)); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(toFileName)); byte[] buff = new byte[32 * 1024]; int len;/*from ww w . ja v a 2s . c o m*/ while ((len = in.read(buff)) > 0) out.write(buff, 0, len); in.close(); out.close(); }
From source file:EOF.java
public static void main(String args[]) { DataInputStream is = null;//from w w w .j a va2 s . c o m byte ch; try { is = new DataInputStream(new FileInputStream("EOF.java")); while (true) { // exception deals catches EOF ch = is.readByte(); System.out.print((char) ch); System.out.flush(); } } catch (EOFException eof) { System.out.println(" >> Normal program termination."); } catch (FileNotFoundException noFile) { System.err.println("File not found! " + noFile); } catch (IOException io) { System.err.println("I/O error occurred: " + io); } catch (Throwable anything) { System.err.println("Abnormal exception caught !: " + anything); } finally { if (is != null) { try { is.close(); } catch (IOException ignored) { } } } }
From source file:Main.java
public static void main(String[] args) { try {/* www. ja va2 s . co m*/ OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os); // create a new FileInputStream to read what we write FileInputStream in = new FileInputStream("test.txt"); // write something in the file writer.write(70); writer.write(71); writer.write(72); // flush the stream writer.flush(); // read what we write for (int i = 0; i < 3; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }