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 { 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 .j a v a 2 s . com } CertPath cp = cf.generateCertPath(mylist); List cplist = cp.getCertificates(); Object[] o = cplist.toArray(); for (int i = 0; i < o.length; i++) { X509Certificate c = (X509Certificate) o[i]; System.out.println(c.getSubjectDN()); byte[] pbk = c.getPublicKey().getEncoded(); for (int j = 0; j < pbk.length; j++) { System.out.print(pbk[j] + ","); } System.out.println("\nIssued by " + c.getIssuerDN()); } }
From source file:Main.java
public static void main(String[] args) throws Exception { byte[] cbuf = new byte[10]; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeUTF("Hello World from java2s.com"); oout.flush();/*from w ww . java2 s. co m*/ oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); ois.read(cbuf, 0, 7); for (int i = 0; i < 7; i++) { System.out.print((char) cbuf[i]); } ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("books.dat"); ObjectOutputStream oos = new ObjectOutputStream(fos); Book book = new Book("1", "Java", "A"); oos.writeObject(book);/*from w w w .ja v a2s. co m*/ oos.flush(); oos.close(); FileInputStream fis = new FileInputStream("books.dat"); ObjectInputStream ois = new ObjectInputStream(fis); book = (Book) ois.readObject(); System.out.println(book.toString()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] b = { 65, 66, 67, 68, 69 }; int i = 0;// w w w . ja v a 2s . co m FileOutputStream fos = new FileOutputStream("C://test.txt"); // writes byte to the output stream fos.write(b, 2, 3); // 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); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] filenames = new String[] { "filename1", "filename2" }; byte[] buf = new byte[1024]; String outFilename = "outfile.zip"; ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename)); for (int i = 0; i < filenames.length; i++) { FileInputStream in = new FileInputStream(filenames[i]); out.putNextEntry(new ZipEntry(filenames[i])); int len;/*from w ww.j a v a 2s . co m*/ while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.closeEntry(); in.close(); } out.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { short[] s = { -5, 32767 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (short j : s) { dos.writeShort(j);/* w ww . j ava 2s . c om*/ } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { int k = dis.readUnsignedShort(); System.out.print(k); } }
From source file:Main.java
public static void main(String[] args) throws Exception { float f = 1.23456f; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeFloat(f);/* w ww .j a v a 2 s . co m*/ oout.writeFloat(1234.56789f); oout.flush(); oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); System.out.println(ois.readFloat()); System.out.println(ois.readFloat()); ois.close(); }
From source file:Main.java
public static void main(String[] a) throws Exception { List list = Arrays.asList(new String[] { "A", "B", "C", "D" }); FileOutputStream fos = new FileOutputStream("list.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(list);//from ww w.ja v a 2 s . c o m oos.close(); FileInputStream fis = new FileInputStream("list.ser"); ObjectInputStream ois = new ObjectInputStream(fis); List anotherList = (List) ois.readObject(); ois.close(); System.out.println(anotherList); }
From source file:MainClass.java
public static void main(String[] a) throws Exception { List list = Arrays.asList(new String[] { "A", "B", "C", "D" }); FileOutputStream fos = new FileOutputStream("list.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(list);//from w w w. j ava2s . c o m oos.close(); FileInputStream fis = new FileInputStream("list.ser"); ObjectInputStream ois = new ObjectInputStream(fis); List anotherList = (List) ois.readObject(); ois.close(); System.out.println(anotherList); }
From source file:Main.java
public static void main(String[] args) { File inputFile = new File("test1.txt"); if (!inputFile.exists()) { System.out.println("The input file " + inputFile.getAbsolutePath() + " does not exist."); System.out.println("Aborted the file reading process."); return;//from www . ja v a 2s.com } try (FileChannel fileChannel = new FileInputStream(inputFile).getChannel()) { ByteBuffer buffer = ByteBuffer.allocate(1024); while (fileChannel.read(buffer) > 0) { buffer.flip(); while (buffer.hasRemaining()) { byte b = buffer.get(); System.out.print((char) b); } buffer.clear(); } } catch (IOException e) { e.printStackTrace(); } }