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 { XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xPath = xPathFactory.newXPath(); InputSource doc = new InputSource(new InputStreamReader(new FileInputStream(new File("file.xml")))); String expression = "//Home/data"; XPathExpression xPathExpression = xPath.compile(expression); NodeList elem1List = (NodeList) xPathExpression.evaluate(doc, XPathConstants.NODESET); xPathExpression = xPath.compile("@type"); for (int i = 0; i < elem1List.getLength(); i++) { System.out.println(xPathExpression.evaluate(elem1List.item(i), XPathConstants.STRING)); }//w w w. j av a2s.c om }
From source file:Main.java
public static void main(String[] args) throws IOException { long[] l = { 1234567890L, 987654321L }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (long j : l) { dos.writeLong(j);/*from w ww. j a va2 s . c om*/ } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { long k = dis.readLong(); System.out.print(k); } }
From source file:Main.java
public static void main(String[] args) throws IOException { int[] i = { 123, 234, 454, 567, 789 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (int j : i) { dos.writeInt(j);/* w w w . j a v a 2 s . c o m*/ } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { int k = dis.readInt(); System.out.print(k); } }
From source file:Main.java
public static void main(String[] args) throws IOException { int[] i = { 123, 234, 345, 456, 678 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (int j : i) { dos.writeInt(j);/*from w w w. ja va 2s . co m*/ } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { int k = dis.readInt(); System.out.print(k); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 65, 66, 67, 68, 69, 70 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (byte b : buf) { dos.writeChar(b);// ww w .jav a 2 s.c o m } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { char c = dis.readChar(); System.out.print(c); } }
From source file:Copy.java
public static void main(String args[]) throws Exception { String elements[] = { "Irish Setter", "Poodle", "English Setter", "Gordon Setter", "Pug" }; Set set = new HashSet(Arrays.asList(elements)); Set set2 = ((Set) ((HashSet) set).clone()); System.out.println(set2);/*from ww w .java 2 s. c o m*/ FileOutputStream fos = new FileOutputStream("set.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(set); oos.close(); FileInputStream fis = new FileInputStream("set.ser"); ObjectInputStream ois = new ObjectInputStream(fis); Set set3 = (Set) ois.readObject(); ois.close(); System.out.println(set3); }
From source file:Main.java
public static void main(String[] args) throws IOException { short[] s = { 123, 234 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (short j : s) { dos.writeShort(j);/*from w ww.ja v a 2 s. c o m*/ } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { short k = dis.readShort(); System.out.print(k); } }
From source file:Main.java
public static void main(String[] args) throws Exception { OutputStream os = new FileOutputStream("C://test.txt"); FilterOutputStream fos = new FilterOutputStream(os); // writes buffer to the output stream fos.write(65);//from ww w .j a va 2 s . c o m // forces byte contents to written out to the stream fos.flush(); // create input streams FileInputStream fis = new FileInputStream("C://test.txt"); // get byte from the file int i = fis.read(); // convert integer to character char c = (char) i; System.out.print("Character read: " + c); fos.close(); fis.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("file.data"))); out.write(1);//w ww . j ava 2 s . co m out.close(); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data"))); byte[] byteArray = new byte[10]; in.read(byteArray); System.out.println(Arrays.toString(byteArray)); in.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] b = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (byte j : b) { dos.writeByte(j);//from ww w . j a v a2 s. c o m } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { int k = dis.read(); System.out.print(k); dis.skipBytes(1); } }