BufferedInputStream input = new BufferedInputStream(sock.getInputStream()); while (!done) { // TODO: Rename btrar to something more meaningful int bytesRead = input.read(btrar); // Do something with the data... }
music=new byte[(int) file.length()];//size & length of the file InputStream is = new FileInputStream (file); BufferedInputStream bis = new BufferedInputStream (is, 8000); DataInputStream dis = new DataInputStream (bis); // Create a DataInputStream to read the audio data from the saved file int i = 0; // Read the file into the "music" array while (dis.available() > 0) { music[i] = dis.readByte(); // This assignment does not reverse the order i++; } dis.close(); // Close the input stream
/** * Skips bytes from the input stream until it finds the <project> * element. * * @throws IOException thrown if an I/O error occurs */ private void skipToProject() throws IOException { final byte[] buffer = new byte[BUFFER_SIZE]; super.mark(BUFFER_SIZE); int count = super.read(buffer, 0, BUFFER_SIZE); while (count > 0) { final int pos = findSequence(PROJECT, buffer); if (pos >= 0) { super.reset(); super.skip(pos); return; } else if (count - PROJECT.length == 0) { return; } super.reset(); super.skip(count - PROJECT.length); super.mark(BUFFER_SIZE); count = super.read(buffer, 0, BUFFER_SIZE); } }
InputStream is = new FileInputStream (file); BufferedInputStream bis = new BufferedInputStream (is, 8000); DataInputStream dis = new DataInputStream (bis); // Create a DataInputStream to read the audio data from the saved file int i = 0; // Read the file into the "music" array while (dis.available() > 0) { music[i] = dis.readShort(); // This assignment does not reverse the order i++; } dis.close(); // Close the input stream
is = new FileInputStream(path + zipname); zis = new ZipInputStream(new BufferedInputStream(is)); ZipEntry ze; byte[] buffer = new byte[1024]; FileOutputStream fout = new FileOutputStream(path + filename); while ((count = zis.read(buffer)) != -1) fout.write(buffer, 0, count); fout.close(); zis.closeEntry();
String docxTemplate = ""; try { br = new BufferedReader(new InputStreamReader(new FileInputStream(targetFile), "UTF-8")); String temp; while( (temp = br.readLine()) != null) fos = new FileOutputStream(targetFile); fos.write(docxTemplate.getBytes("UTF-8")); fos.close(); response.setHeader("Content-Length",String.valueOf(generatedFile.length())); input = new BufferedInputStream(new FileInputStream(generatedFile), 10240); output = new BufferedOutputStream(response.getOutputStream(), 10240); for (int length; (length = input.read(buffer)) > 0;) { output.write(buffer, 0, length); input.close(); output.close(); InputStream in = new FileInputStream(file); try { copy(in, out);
FileInputStream inputStream = new FileInputStream(filePath); ZipInputStream zipStream = new ZipInputStream(inputStream); ZipEntry zEntry = null; hanldeDirectory(zEntry.getName()); } else { FileOutputStream fout = new FileOutputStream( this.destination + "/" + zEntry.getName()); BufferedOutputStream bufout = new BufferedOutputStream(fout); byte[] buffer = new byte[1024]; int read = 0; while ((read = zipStream.read(buffer)) != -1) { bufout.write(buffer, 0, read); bufout.close(); fout.close();
FileInputStream fileInputStream = new FileInputStream(new File(existingFileName)); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary); dos = new DataOutputStream(conn.getOutputStream()); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + existingFileName + "\"" + lineEnd); dos.writeBytes(lineEnd); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; bytesRead = fileInputStream.read(buffer, 0, bufferSize); fileInputStream.close(); dos.flush(); dos.close(); inStream = new DataInputStream(conn.getInputStream()); String str; while ((str = inStream.readLine()) != null) { inStream.close();
DataOutputStream out = new DataOutputStream(new FileOutputStream("MyFile.txt")); out.writeInt(20); out.writeInt(53432542); out.writeLong(5234843258938L); out.close(); DataInputStream in = new DataInputStream(new FileInputStream("MyFile.txt")); System.out.println(in.readInt()); System.out.println(in.readInt()); System.out.println(in.readLong()); in.close();
void savefile(URI sourceuri) { String sourceFilename= sourceuri.getPath(); String destinationFilename = android.os.Environment.getExternalStorageDirectory().getPath()+File.separatorChar+"abc.mp3"; BufferedInputStream bis = null; BufferedOutputStream bos = null; try { bis = new BufferedInputStream(new FileInputStream(sourceFilename)); bos = new BufferedOutputStream(new FileOutputStream(destinationFilename, false)); byte[] buf = new byte[1024]; bis.read(buf); do { bos.write(buf); } while(bis.read(buf) != -1); } catch (IOException e) { } finally { try { if (bis != null) bis.close(); if (bos != null) bos.close(); } catch (IOException e) { } } }
File f = new File("path-to-your-file"); DataInputStream dis = new DataInputStream(new FileInputStream(f)); //to read the file byte[] b = new byte[(int)f.length()]; //to store the bytes int l = dis.read(b); //stores the bytes in b dis.close(); DataOutputStream dos = new DataOutputStream(new FileOutputStream(new File("new-file"))); // to write the file dos.write(b,0,l); //writes the bytes from b to the file dos.close();
DataInputStream reader = new DataInputStream(new FileInputStream( backup)); reader.readFully(data); reader.close(); DataOutputStream writer = new DataOutputStream( new FileOutputStream(output)); IvParameterSpec vector = new IvParameterSpec(iv); cipher.init(Cipher.DECRYPT_MODE, secret, vector); writer.write(cipher.update(data)); writer.write(cipher.doFinal()); writer.close(); } catch (NoSuchAlgorithmException e) { Log.e(TAG, "Could not acquire hash algorithm!", e);
String filename = "text.dat"; DataOutputStream dos = new DataOutputStream(new FileOutputStream(filename)); for (int i = 0; i < 4; i++) dos.write(0xA9); dos.close(); DataInputStream dis = new DataInputStream(new FileInputStream(filename)); for (int i = 0; i < 4; i++) System.out.println(Integer.toHexString(dis.readUnsignedByte())); dis.close();
DataOutputStream dos = new DataOutputStream(new FileOutputStream("Text.t")); dos.writeUTF(String.valueOf(10101010)); DataInputStream dis = new DataInputStream(new FileInputStream("Text.t")); System.out.println(dis.readUTF()); dos.close(); dis.close();
public class Test { public static void main(String[] args) throws Exception { DataOutputStream dos = new DataOutputStream(new FileOutputStream("a.bin")); dos.writeDouble(1.2); dos.writeDouble(3.4); dos.close(); DataInputStream dis = new DataInputStream(new FileInputStream("a.bin")); System.out.println(dis.readDouble()); System.out.println(dis.readDouble()); dis.close(); } }
int sum; stream = new BufferedInputStream(new FileInputStream(file)); data = new byte[(int)file.length()]; soFar = 0; int sum; stream = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); fileSize = (int)file.length(); sum = 0; sum += stream.readByte(); stream.close(); int sum; stream = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); data = new byte[(int)file.length()]; stream.readFully(data); stream.close(); stream.close();
File file = new File("myFile"); byte[] fileData = new byte[(int) file.length()]; DataInputStream dis = new DataInputStream(new FileInputStream(file)); dis.readFully(fileData); dis.close();
response.setContentType("application/force-download"); response.setContentLength((int)f.length()); //response.setContentLength(-1); response.setHeader("Content-Transfer-Encoding", "binary"); response.setHeader("Content-Disposition","attachment; filename=\"" + "xxx\"");//fileName); ... ... File f= new File(fileName); InputStream in = new FileInputStream(f); BufferedInputStream bin = new BufferedInputStream(in); DataInputStream din = new DataInputStream(bin); while(din.available() > 0){ out.print(din.readLine()); out.print("\n"); }
ucon = url.openConnection(); InputStream is = ucon.getInputStream(); BufferedInputStream inStream = new BufferedInputStream(is, 1024 * 5); FileOutputStream outStream = new FileOutputStream(file); byte[] buff = new byte[5 * 1024]; while ((len = inStream.read(buff)) != -1) { outStream.write(buff, 0, len); outStream.close(); inStream.close();
File file = new File("C:/text.bin"); DataInputStream stream = new DataInputStream(new FileInputStream(file)); boolean isTrue = stream.readBoolean(); int value = stream.readInt(); stream.close(); System.out.printlin(isTrue + " " + value);