ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeLong(someLong); dos.close(); byte[] longBytes = baos.toByteArray();
File file = new File("C:/text.bin"); file.createNewFile(); DataOutputStream stream = new DataOutputStream(new FileOutputStream(file)); stream.writeBoolean(true); stream.writeInt(1234); stream.close();
Process process = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(process.getOutputStream()); String cmd = "/system/bin/input tap 100 200\n"; os.writeBytes(cmd); os.writeBytes("exit\n"); os.flush(); os.close(); process.waitFor();
BufferedInputStream bis = new BufferedInputStream(entity.getContent()); String filePath = "sample.txt"; BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(filePath))); int inByte; while((inByte = bis.read()) != -1) bos.write(inByte); bis.close(); bos.close();
private static void downloadFile(String url, File outputFile) { try { URL u = new URL(url); URLConnection conn = u.openConnection(); int contentLength = conn.getContentLength(); DataInputStream stream = new DataInputStream(u.openStream()); byte[] buffer = new byte[contentLength]; stream.readFully(buffer); stream.close(); DataOutputStream fos = new DataOutputStream(new FileOutputStream(outputFile)); fos.write(buffer); fos.flush(); fos.close(); } catch(FileNotFoundException e) { return; // swallow a 404 } catch (IOException e) { return; // swallow a 404 } }
URL url = new URL(aurl[0]); URLConnection conexion = url.openConnection(); conexion.connect(); int lenghtOfFile = conexion.getContentLength(); InputStream input = new BufferedInputStream(url.openStream()); OutputStream output = new FileOutputStream(StorezipFileLocation); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); outputStream.close(); inputStream.close();
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(name), 64*1024)); dos.writeInt(numbers.length); for (int number : numbers) dos.writeInt(number); dos.close();
output = new DataOutputStream(new BufferedOutputStream(out)); output.close(); output = null;
Socket socket = ...; // Create and connect the socket DataOutputStream dOut = new DataOutputStream(socket.getOutputStream()); // Send first message dOut.writeByte(1); dOut.writeUTF("This is the first type of message."); dOut.flush(); // Send off the data // Send the second message dOut.writeByte(2); dOut.writeUTF("This is the second type of message."); dOut.flush(); // Send off the data // Send the third message dOut.writeByte(3); dOut.writeUTF("This is the third type of message (Part 1)."); dOut.writeUTF("This is the third type of message (Part 2)."); dOut.flush(); // Send off the data // Send the exit message dOut.writeByte(-1); dOut.flush(); dOut.close();
DataOutputStream os = new DataOutputStream(this.socket.getOutputStream()); os.writeBytes("200"); os.close(); br.close(); socket.close();
URL url = new URL(targetURL); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", DataOutputStream wr = new DataOutputStream ( connection.getOutputStream()); wr.writeBytes(urlParameters); wr.close();
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(yourFile)); bos.write(fileBytes); bos.flush(); bos.close();
String fileType = rs.getString("FILETYPE_COL_NAME"); DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("filepath."+fileType ))); ResultSet rs = statement.executeQuery("Select * from tablename"); BufferedInputStream bis = new BufferedInputStream(rs.getBinaryStream("BLOB_COL_NAME")); byte[] buffer = new byte[1024]; int byteread = 0; while((byteread = bis.read(buffer)) != -1){ dos.write(buffer, 0, byteread); } dos.flush(); dos.close(); bis.close();
int i = 42; DataOutputStream os = new DataOutputStream(new FileOutputStream("C:\\binout.dat")); os.writeInt(i); os.close();
BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream()); DataOutputStream dos = new DataOutputStream(bos); dos.close();
DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(wr, "UTF-8")); writer.write(content); writer.close(); wr.close();
url = new URL("http://localhost:8080/putservice"); } catch (MalformedURLException exception) { exception.printStackTrace(); DataOutputStream dataOutputStream = null; try { httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); httpURLConnection.setRequestMethod("PUT"); httpURLConnection.setDoInput(true); httpURLConnection.setDoOutput(true); dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream()); dataOutputStream.write("hello"); } catch (IOException exception) { if (dataOutputStream != null) { try { dataOutputStream.flush(); dataOutputStream.close(); } catch (IOException exception) { exception.printStackTrace();
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "your_folder_on_sd", "file_name"); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); byte[] yourKey = generateKey("password"); byte[] filesBytes = encodeFile(yourKey, yourByteArrayContainigDataToEncrypt); bos.write(fileBytes); bos.flush(); bos.close();
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("abc.txt"), 32 * 1024)); long start = System.nanoTime(); final int count = 220000000; for (int i = 0; i < count; i++) { long l = i; dos.writeLong(l); } dos.close(); long time = System.nanoTime() - start; System.out.printf("Took %.3f seconds to write %,d longs%n", time / 1e9, count);
DataOutputStream writer = new DataOutputStream( new FileOutputStream(output)); writer.write(cipher.update(data)); writer.write(cipher.doFinal()); writer.close(); } catch (NoSuchAlgorithmException e) { Log.e(TAG, "Could not acquire hash algorithm!", e);