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);
byte[] test = new byte[] {0, 0, 1, 0, 0, 0, 1, 1, 8, 9}; DataInputStream stream = new DataInputStream(new ByteArrayInputStream(test)); int value0 = stream.readInt(); int value1 = stream.readInt(); byte value2 = stream.readByte(); byte value3 = stream.readByte(); stream.close(); System.out.println(value0 + " " + value1 + " " + value2 + " " + value3);
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
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 } }
private String readTextFile(String fName) { String result = null; FileConnection fconn = null; DataInputStream is = null; try { fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE); is = fconn.openDataInputStream(); byte[] data = IOUtilities.streamToBytes(is); result = new String(data); } catch (IOException e) { System.out.println(e.getMessage()); } finally { try { if (null != is) is.close(); if (null != fconn) fconn.close(); } catch (IOException e) { System.out.println(e.getMessage()); } } return result; }
File myFile = new File("test.au"); byte[] samples; AudioInputStream is = AudioSystem.getAudioInputStream(myFile); DataInputStream dis = new DataInputStream(is); //So we can use readFully() try { AudioFormat format = is.getFormat(); samples = new byte[(int)(is.getFrameLength() * format.getFrameSize())]; dis.readFully(samples); } finally { dis.close(); }
FileInputStream fis; final StringBuffer storedString = new StringBuffer(); try { fis = openFileInput("out.txt"); DataInputStream dataIO = new DataInputStream(fis); String strLine = null; if ((strLine = dataIO.readLine()) != null) { storedString.append(strLine); } dataIO.close(); fis.close(); } catch (Exception e) { }
File file = new File("myFile"); byte[] fileData = new byte[(int) file.length()]; DataInputStream dis = new DataInputStream(new FileInputStream(file)); dis.readFully(fileData); dis.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); fileInputStream.close(); dos.flush(); dos.close(); inStream = new DataInputStream(conn.getInputStream()); String str; inStream.close();
ServerSocket ss=new ServerSocket(6666); Socket s=ss.accept();//establishes connection DataInputStream dis=new DataInputStream(s.getInputStream()); String str=dis.readUTF(); System.out.println("message= "+str); dis.close();
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
import java.io.*; public class ClassVersionChecker { public static void main(String[] args) throws IOException { for (int i = 0; i < args.length; i++) checkClassVersion(args[i]); } private static void checkClassVersion(String filename) throws IOException { DataInputStream in = new DataInputStream (new FileInputStream(filename)); int magic = in.readInt(); if(magic != 0xcafebabe) { System.out.println(filename + " is not a valid class!");; } int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); System.out.println(filename + ": " + major + " . " + minor); in.close(); } }
try{ 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); fileInputStream.close(); dos.flush(); dos.close(); inStream = new DataInputStream ( conn.getInputStream() ); String str; while (( str = inStream.readLine()) != null){ reponse_data=str; inStream.close();
InputStream input = context.getAssets().open(fileName); DataInputStream in = new DataInputStream(input); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { // Print the content on the console System.out.println (strLine); } //Close the input stream in.close(); } catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); }
InputStream is = new FileInputStream(pcmFile); BufferedInputStream bis = new BufferedInputStream(is); dis = new DataInputStream(bis); if (dis != null) { try { dis.close(); } catch (IOException e) {
do { Object foo = new Reloader().loadClass("MyFoo").newInstance(); System.out.println("LOADED: " + foo); // Overload MyFoo#toString() for effect System.out.println("Press <ENTER> when MyFoo.class has changed"); System.in.read(); } while (true); File f = new File("bin/" + className.replaceAll("\\.", "/") + ".class"); int size = (int) f.length(); byte buff[] = new byte[size]; FileInputStream fis = new FileInputStream(f); DataInputStream dis = new DataInputStream(fis); dis.readFully(buff); dis.close(); return buff;
input = new DataInputStream(new BufferedInputStream(in)); input.close(); input = null; output = new DataOutputStream(new BufferedOutputStream(out)); output.close(); output = null;
DataInputStream dis = new DataInputStream(System.in); StringBuffer inputLine = new StringBuffer(); String tmp; while ((tmp = dis.readLine()) != null) { inputLine.append(tmp); System.out.println(tmp); } dis.close();