List of usage examples for java.io FileInputStream read
public int read(byte b[]) throws IOException
b.length
bytes of data from this input stream into an array of bytes. From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("C:/String.txt"); FileInputStream fin = new FileInputStream(file); byte fileContent[] = new byte[(int) file.length()]; fin.read(fileContent); System.out.println(new String(fileContent)); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] bs = new byte[4]; FileInputStream fis = new FileInputStream("C://test.txt"); // read bytes to the buffer int i = fis.read(bs); System.out.println("Number of bytes read: " + i); // for each byte in buffer for (byte b : bs) { // converts byte to character char c = (char) b; System.out.println(c);//from ww w.ja v a 2s .co m } }
From source file:Main.java
public static void main(String[] argv) throws Exception { GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream("outfile.gzip")); FileInputStream in = new FileInputStream("infilename"); byte[] buf = new byte[1024]; int len;// w w w . j a v a2 s . com while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.finish(); out.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String outFilename = "outfile.gzip"; GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(outFilename)); String inFilename = "infilename"; FileInputStream in = new FileInputStream(inFilename); byte[] buf = new byte[1024]; int len;//from w w w. ja v a 2 s. c om while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.finish(); out.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println("Usage: Masher filename"); return;// ww w .j a va 2 s . co m } MessageDigest md = MessageDigest.getInstance("MD5"); FileInputStream in = new FileInputStream(args[0]); byte[] buffer = new byte[8192]; int length; while ((length = in.read(buffer)) != -1) md.update(buffer, 0, length); byte[] raw = md.digest(); BASE64Encoder encoder = new BASE64Encoder(); String base64 = encoder.encode(raw); System.out.println(base64); }
From source file:Main.java
public static void main(String[] args) throws IOException { Deflater def = new Deflater(); byte[] input = new byte[1024]; byte[] output = new byte[1024]; FileInputStream fin = new FileInputStream("a.dat"); FileOutputStream fout = new FileOutputStream("b.dat"); int numRead = fin.read(input); def.setInput(input, 0, numRead);/*from www . j av a 2 s . c om*/ while (!def.needsInput()) { int numCompressedBytes = def.deflate(output, 0, output.length); if (numCompressedBytes > 0) { fout.write(output, 0, numCompressedBytes); } } def.finish(); fin.close(); fout.flush(); fout.close(); def.reset(); }
From source file:config.MainClass.java
/** * @param args the command line arguments *//*from w w w. j a va 2 s . c o m*/ public static void main(String[] args) { // TODO code application logic here File file = new File("D:\\iti images\\Dish Party_6-11-2014\\IMG_5376.jpg"); byte[] bFile = new byte[(int) file.length()]; try { FileInputStream fileInputStream = new FileInputStream(file); //convert file into array of bytes fileInputStream.read(bFile); fileInputStream.close(); } catch (Exception e) { System.out.println("Error in reading the image"); } UserData data = new UserData(); data.setUserName("hasby allah"); data.setBirthday(new Date()); data.setPhone("65656"); data.setFullName("7asby allah w n3m el wakel"); data.setAddress("haram"); data.setPassword("password"); data.setImage(bFile); AbstractApplicationContext fact = new ClassPathXmlApplicationContext("SpringConfig.xml"); DaoService serviceInterface = fact.getBean(DaoService.class); serviceInterface.save(data); }
From source file:MainClass.java
public static void main(String[] args) { File originFile = new File("c:\\file1.txt"); File destinationFile = new File("c:\\file1.txt"); if (!originFile.exists() || destinationFile.exists()) { return;/*from w w w . ja va 2 s .co m*/ } try { byte[] readData = new byte[1024]; FileInputStream fis = new FileInputStream(originFile); FileOutputStream fos = new FileOutputStream(destinationFile); int i = fis.read(readData); while (i != -1) { fos.write(readData, 0, i); i = fis.read(readData); } fis.close(); fos.close(); } catch (IOException e) { System.out.println(e); } }
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;/*www . j a v a 2 s . c o 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[] argv) throws Exception { FileInputStream fin = new FileInputStream("text.txt"); int len;/*from w w w . java 2 s.com*/ byte data[] = new byte[16]; // Read bytes until EOF is encountered. do { len = fin.read(data); for (int j = 0; j < len; j++) System.out.printf("%02X ", data[j]); } while (len != -1); }