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 { String s = "Hello World from java2s.com!"; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeUTF(s);/* w w w . j a va 2s . com*/ oout.writeUTF("This is an example from java2s.com"); oout.flush(); oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); System.out.println(ois.readUTF()); System.out.println(ois.readUTF()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { long l = 12345678909876L; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeLong(l);//from w ww . j a v a 2 s. c o m oout.writeLong(987654321L); oout.flush(); oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); System.out.println(ois.readLine()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(); st.executeUpdate("create table survey (Id int, b BLOB);"); PreparedStatement pstmt = conn.prepareStatement("INSERT INTO survey VALUES(1,?)"); File file = new File("blob.txt"); FileInputStream fis = new FileInputStream(file); pstmt.setBinaryStream(1, fis, (int) file.length()); pstmt.execute();/*from www. j av a 2 s . co m*/ fis.close(); st.close(); conn.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("java2s.com".getBytes()); out.close();//from w w w . j a v a 2 s . c o m 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:InputOutputDemoObjectBinaryFile.java
public static void main(String[] a) throws Exception { //Write an object or array to binary file "java2sObject.dat": ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("java2sObject.dat")); oos.writeObject(new int[] { 2, 3, 5, 7, 11 }); oos.close();/*w ww. j a va 2s . com*/ //Read objects or arrays from binary file "o.dat": ObjectInputStream ois = new ObjectInputStream(new FileInputStream("java2sObject.dat")); int[] ia = (int[]) (ois.readObject()); System.out.println(ia[0] + "," + ia[1] + "," + ia[2] + "," + ia[3] + "," + ia[4]); }
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 va 2s . co m } CertStoreParameters cparam = new CollectionCertStoreParameters(mylist); CertStore cs = CertStore.getInstance("Collection", cparam); System.out.println(cs.getCertStoreParameters()); System.out.println(cs.getProvider()); System.out.println(cs.getType()); }
From source file:Main.java
public static void main(String[] args) throws IOException { float[] fbuf = { 12.34f, 23.34f, 45.56f, 67.78f, 12.55f, 77.88f }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (float f : fbuf) { dos.writeFloat(f);/* www . j a v a 2 s . com*/ } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { float c = dis.readFloat(); System.out.print(c); } }
From source file:Main.java
public static void main(String[] args) throws IOException { ServerSocket servsock = new ServerSocket(123456); File myFile = new File("s.pdf"); while (true) {//from w w w . j ava 2 s . co m Socket sock = servsock.accept(); byte[] mybytearray = new byte[(int) myFile.length()]; BufferedInputStream bis = new BufferedInputStream(new FileInputStream(myFile)); bis.read(mybytearray, 0, mybytearray.length); OutputStream os = sock.getOutputStream(); os.write(mybytearray, 0, mybytearray.length); os.flush(); sock.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); // write something in the file oout.writeUTF("Hello World from java2s.com"); oout.flush();/*from ww w.java2s . c o m*/ // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read from the stream for (int i = 0; i < ois.available();) { System.out.print((char) ois.read()); } ois.close(); }
From source file:EntityReferenceTest.java
public static void main(String[] args) throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream("e.xml")); while (reader.hasNext()) { int event = reader.next(); if (event == XMLStreamConstants.CHARACTERS) System.out.println(reader.getText()); else if (event == XMLStreamConstants.ENTITY_REFERENCE) { System.out.println("en: " + reader.getLocalName()); System.out.println("er: " + reader.getText()); }/*from w ww. ja va2 s .c om*/ } inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); reader = inputFactory.createXMLStreamReader(new FileInputStream("e.xml")); while (reader.hasNext()) { int event = reader.next(); if (event == XMLStreamConstants.CHARACTERS) System.out.println(reader.getText()); else if (event == XMLStreamConstants.ENTITY_REFERENCE) { System.out.println("en: " + reader.getLocalName()); System.out.println("er: " + reader.getText()); } } }