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 { int i = 123456; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeInt(i);/* w w w . jav a 2 s . c o m*/ oout.writeInt(54321); oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print an int System.out.println(ois.readInt()); // read and print an int System.out.println(ois.readInt()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { byte[] buffer = { 65, 66, 67, 68, 69 }; int i = 0;//w w w. j ava2s. c o m OutputStream os = new FileOutputStream("C://test.txt"); FilterOutputStream fos = new FilterOutputStream(os); // writes buffer to the output stream fos.write(buffer, 2, 3); // forces byte contents to written out to the stream fos.flush(); // create input streams FileInputStream fis = new FileInputStream("C://test.txt"); while ((i = fis.read()) != -1) { // converts integer to the character char c = (char) i; System.out.println("Character read: " + c); } fos.close(); fis.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeObject(new Example()); oout.flush();//from w w w.j av a 2s. c om oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); Example a = (Example) ois.readObject(); System.out.println(a.s); a.validateObject(); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { XPathFactory xpf = XPathFactory.newInstance(); XPath xp = xpf.newXPath();//www . ja va2 s. c om xp.setNamespaceContext(new MyNamespaceContext()); XPathExpression xpe = xp.compile("ns:feed/ns:entry"); FileInputStream xmlStream = new FileInputStream("input.xml"); InputSource xmlInput = new InputSource(xmlStream); Element result = (Element) xpe.evaluate(xmlInput, XPathConstants.NODE); System.out.println(result); }
From source file:SerializationUtilsTrial.java
public static void main(String[] args) { try {/*from www . j a va 2s. c om*/ // File to serialize object to String fileName = "testSerialization.ser"; // New file output stream for the file FileOutputStream fos = new FileOutputStream(fileName); // Serialize String SerializationUtils.serialize("SERIALIZE THIS", fos); fos.close(); // Open FileInputStream to the file FileInputStream fis = new FileInputStream(fileName); // Deserialize and cast into String String ser = (String) SerializationUtils.deserialize(fis); System.out.println(ser); fis.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { String filename = System.getProperty("java.home") + "/lib/security/cacerts".replace('/', File.separatorChar); FileInputStream is = new FileInputStream(filename); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); String password = "password"; keystore.load(is, password.toCharArray()); PKIXParameters params = new PKIXParameters(keystore); params.setRevocationEnabled(false);//from ww w. j a va 2s. c om CertPathValidator certPathValidator = CertPathValidator.getInstance(CertPathValidator.getDefaultType()); CertPath certPath = null; CertPathValidatorResult result = certPathValidator.validate(certPath, params); PKIXCertPathValidatorResult pkixResult = (PKIXCertPathValidatorResult) result; TrustAnchor ta = pkixResult.getTrustAnchor(); X509Certificate cert = ta.getTrustedCert(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { TransformerFactory factory = TransformerFactory.newInstance(); Templates template = factory.newTemplates(new StreamSource(new FileInputStream("xsl.xlt"))); Transformer xformer = template.newTransformer(); Source source = new StreamSource(new FileInputStream("in.xml")); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.newDocument(); Result result = new DOMResult(doc); xformer.transform(source, result);//from w w w. j ava 2 s.c o m }
From source file:Main.java
public static void main(String[] argv) throws Exception { double data[] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6 }; DataOutputStream fout = new DataOutputStream(new DeflaterOutputStream(new FileOutputStream("data.dat"))); fout.writeInt(data.length);//from ww w .j av a 2s . c o m for (double d : data) fout.writeDouble(d); DataInputStream fin = new DataInputStream(new InflaterInputStream(new FileInputStream("data.dat"))); int num = fin.readInt(); double avg = 0.0; double d; for (int i = 0; i < num; i++) { d = fin.readDouble(); avg += d; System.out.print(d + " "); } fin.close(); fout.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { short s = 56; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeShort(s);//w w w. j a v a 2s . co m oout.writeShort(new Short("1")); oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print a short System.out.println(ois.readShort()); // read and print a short System.out.println(ois.readShort()); ois.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { InputSource in = new InputSource(new FileInputStream("y.xml")); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setNamespaceAware(true);//from www . jav a 2 s.c om Document doc = dfactory.newDocumentBuilder().parse(in); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); CachedXPathAPI path = new CachedXPathAPI(); NodeIterator nl = path.selectNodeIterator(doc, "\\abc\\"); Node n; while ((n = nl.nextNode()) != null) transformer.transform(new DOMSource(n), new StreamResult(new OutputStreamWriter(System.out))); }