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[] args) throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLEventReader reader = inputFactory.createXMLEventReader(new FileInputStream(new File("a.xml"))); reader = inputFactory.createFilteredReader(reader, new EventFilter() { public boolean accept(XMLEvent event) { return false; }//from w ww . j a v a2 s . com }); reader = inputFactory.createFilteredReader(reader, new ElementOnlyFilter()); System.out.println(reader.hasNext()); System.out.println(reader.next()); }
From source file:Main.java
public static void main(String[] atgs) throws Exception { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("java.txt"))); out.writeUTF(""); out.writeBytes("a"); out.writeChars("aaa"); out.close();/*from ww w .ja v a2 s . c o m*/ DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("java.txt"))); System.out.println(in.readUTF()); byte[] buf = new byte[1024]; int len = in.read(buf); System.out.println(new String(buf, 0, len)); in.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.writeByte(1);/*from w w w . 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 Exception { ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("file.data"))); out.writeShort(1);//from ww w .ja v a 2 s .c o 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 Exception { String s = "Hello World!"; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeUTF(s);//w w w .ja v a 2 s .co m oout.writeUTF("This is an example from java2s.com"); oout.flush(); oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); ois.skipBytes(4); for (int i = 0; i < ois.available() - 4; i++) { System.out.print((char) ois.readByte()); } ois.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.writeChar(100);//from ww w . ja va2s .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 { String[] s = { "Hello", "tutorial from java2s.com!!" }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (String j : s) { dos.writeUTF(j);// w ww . j a va2s . c o m } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { String k = dis.readUTF(); System.out.print(k); } }
From source file:Main.java
public static void main(String[] args) throws IOException { String[] s = { "Hello", "from java2s.com!" }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (String j : s) { dos.writeUTF(j);//from w ww . j av a 2 s .c o m } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { String k = dis.readUTF(); System.out.print(k); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { char[] passphrase = "sasquatch".toCharArray(); KeyStore keystore = KeyStore.getInstance("JKS"); keystore.load(new FileInputStream(".keystore"), passphrase); TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); tmf.init(keystore);//from ww w . j a va2 s . c om SSLContext context = SSLContext.getInstance("TLS"); TrustManager[] trustManagers = tmf.getTrustManagers(); context.init(null, trustManagers, null); SSLSocketFactory sf = context.getSocketFactory(); Socket s = sf.createSocket(HOST, PORT); OutputStream out = s.getOutputStream(); out.write("\nConnection established.\n\n".getBytes()); int theCharacter = 0; theCharacter = System.in.read(); while (theCharacter != '~') // The '~' is an escape character to exit { out.write(theCharacter); out.flush(); theCharacter = System.in.read(); } out.close(); s.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.writeDouble(1.234);// www.j av a 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(); }