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 { Properties prop = new Properties(); String s = "Chapter Count=200"; String s2 = "Tutorial Count=15"; // create a new input and output stream FileOutputStream fos = new FileOutputStream("properties.txt"); FileInputStream fis = new FileInputStream("properties.txt"); // write the first property in the output stream file fos.write(s.getBytes());// w w w. j a v a2s. c om // change the line between the two properties fos.write("\n".getBytes()); // write next property fos.write(s2.getBytes()); // load from input stream prop.load(fis); // print the properties list from System.out prop.list(System.out); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { String storename = args[0];/* www . ja va 2 s.co m*/ char[] storepass = args[1].toCharArray(); String alias = args[2]; KeyStore ks = KeyStore.getInstance("JKS"); ks.load(new FileInputStream(storename), storepass); java.security.cert.Certificate[] cchain = ks.getCertificateChain(alias); List mylist = new ArrayList(); for (int i = 0; i < cchain.length; i++) { mylist.add(cchain[i]); } CertificateFactory cf = CertificateFactory.getInstance("X.509"); CertPath cp = cf.generateCertPath(mylist); System.out.println(cp); }
From source file:Main.java
public static void main(String[] argv) throws Exception { //Read from an input stream InputStream is = new BufferedInputStream(new FileInputStream("source.gif")); Image image = ImageIO.read(is); JFrame frame = new JFrame(); JLabel label = new JLabel(new ImageIcon(image)); frame.getContentPane().add(label, BorderLayout.CENTER); frame.pack();/*from ww w.j av a 2 s .c om*/ frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { FileChannel fc = new FileOutputStream("data2.txt").getChannel(); fc.write(ByteBuffer.wrap("Some text".getBytes())); fc.close();//from www . j a v a2 s. co m fc = new FileInputStream("data2.txt").getChannel(); ByteBuffer buff = ByteBuffer.allocate(BSIZE); fc.read(buff); buff.flip(); System.out.println(buff.asCharBuffer()); // Decode using this system's default Charset: buff.rewind(); String encoding = System.getProperty("file.encoding"); System.out.println("Decoded using " + encoding + ": " + Charset.forName(encoding).decode(buff)); // Or, we could encode with something that will print: fc = new FileOutputStream("data2.txt").getChannel(); fc.write(ByteBuffer.wrap("Some text".getBytes("UTF-16BE"))); fc.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String zipname = "d.zip"; CheckedInputStream checksum = new CheckedInputStream(new FileInputStream(zipname), new Adler32()); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum)); ZipEntry entry;//from w w w. java 2 s . c o m while ((entry = zis.getNextEntry()) != null) { System.out.println("Unzipping: " + entry.getName()); int size; byte[] buffer = new byte[2048]; BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(entry.getName()), buffer.length); while ((size = zis.read(buffer, 0, buffer.length)) != -1) { bos.write(buffer, 0, size); } bos.flush(); bos.close(); } zis.close(); System.out.println("Checksum = " + checksum.getChecksum().getValue()); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { CertificateFactory cf = CertificateFactory.getInstance("X.509"); List mylist = new ArrayList(); for (int i = 0; i < args.length; i++) { FileInputStream in = new FileInputStream(args[i]); Certificate c = cf.generateCertificate(in); mylist.add(c);/*from w w w. ja v a2 s .c o m*/ } CertPath cp = cf.generateCertPath(mylist); System.out.println(cp); }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory(); XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(new FileInputStream("input.xml")); InterestingElementFilter filter = new InterestingElementFilter(); XMLEventReader interestingElementReader = xmlInputFactory.createFilteredReader(xmlEventReader, filter); while (interestingElementReader.hasNext()) { XMLEvent xmlEvent = interestingElementReader.peek(); if (xmlEvent.isStartElement()) { System.out.println(xmlEvent.asStartElement().getName()); }//from w w w. j a v a 2 s . c o m interestingElementReader.next(); } }
From source file:Main.java
public static void main(String[] args) { Path copy_from_2 = Paths.get("C:/tutorial/Java/JavaFX", "tutor.txt"); Path copy_to_2 = Paths.get("C:/tutorial/Java/Swing", "tutor.txt"); try (InputStream is = new FileInputStream(copy_from_2.toFile())) { Files.copy(is, copy_to_2, REPLACE_EXISTING); } catch (IOException e) { System.err.println(e);//from w w w .j av a2 s. c o m } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String operatingSystem = (String) System.getProperty("os.name"); String javaVersion = (String) System.getProperty("java.version"); String javaDirectory = (String) System.getProperty("java.home"); String userHomeDir = (String) System.getProperty("user.home"); String myFile = (String) System.getProperty("myFile"); FileInputStream fin = new FileInputStream(myFile); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] b = { 65, 66, 67, 68, 69 }; int i = 0;//from w ww.ja v a 2s .c om FileOutputStream fos = new FileOutputStream("C://test.txt"); fos.write(b); // flushes the content to the underlying stream fos.flush(); // create new file input stream FileInputStream fis = new FileInputStream("C://test.txt"); // read till the end of the file while ((i = fis.read()) != -1) { // convert integer to character char c = (char) i; System.out.print(c); } }