DataInputStream « API « Java I/O Q&A





1. When can DataInputStream.skipBytes(n) not skip n bytes?    stackoverflow.com

The Sun Documentation for DataInput.skipBytes states that it "makes an attempt to skip over n bytes of data from the input stream, discarding the skipped bytes. However, it may ...

2. Java's DataInputStream.readUTF and number of bytes read    stackoverflow.com

I am writing a custom archive format in JAVA (J2ME to be precise). The archiver works OK, however I have little problems with de-archiving. How could I know how many bytes have ...

3. Difference between skipBytes and skip of DataInputStream?    stackoverflow.com

I wonder now, what is the difference between the two methods: DataInputStream.skipBytes and DataInputStream.skip. I am aware of the fact that skip must come from InputStream and skipBytes from DataInput, but still, is ...

4. DataInputStream and UTF-8    stackoverflow.com

I'm kind of a new programmer, and I'm having a couple of problems with the code I'm handling. Basically what the code does is receive a form from another JSP, read the ...

5. Help with DataInputStream    stackoverflow.com

I am learning to read and write in Java and am stucj with a simple exercise. The program reads from 2 txt files that contain each numbers in rows and write ...

6. java initializing variable for stream in/out    stackoverflow.com

hi i have a problem with this code... it s not clear how i can initialize the variables of in/out during the creation of this object the program ...

7. How can I recognize a special delimiter string when reading from a file of strings?    stackoverflow.com

I want to read strings from a file. When a certain string (><) is found, I want to start reading integers instead, and convert them to binary strings. My program is reading ...

8. Java DataInputStream read operations throwing Exceptions    stackoverflow.com

I'm trying to familiarize myself with Java IO classes, so I wrote the code below:

public static void main(String[] args)throws IOException {
    FileOutputStream fos = new FileOutputStream("fileIO.txt");
   ...

9. little endian DataInputStream    stackoverflow.com

Is there any way to force DataInputStream to read little-endian data?? Thx PS. Doing byte-buffer conversions is not very convinient as I'm dealing with C-type structs that have lots of 32-bit and ...





10. DataInputStream    stackoverflow.com

can someone help me? Im new to using io package. this is a homework. Assume you have created a DataInputStream object named aDataInStream to read values from a binary file. Provide the ...

11. How to read parts of binary file again if DataInputStream does not support mark/reset    stackoverflow.com

I need to read a section of a structured binary file by passing an index. However, DataInputStream does not support mark/reset. How can I achieve what I want? Are ...

12. Hi friends. I want DataInputStream to read Korean language from a webpage using java but it doesn't display the contents I want. How do I?    stackoverflow.com

Example shown here how I do it at http://leepoint.net/notes-java/io/20internet/10readpage.html . But what if the website it reads contains Korean languages? (Or maybe Chinese languages if you can?) How to make ...

13. DataInputStream    coderanch.com

14. DataInputStream.readInt() vs. reading 4 bytes    coderanch.com

Hi, I am trying to read 4 bytes from a file using the DataInputStream, but I am not getting the correct integer back. If I use the readInt() method, I get -8355712 which is what I am expecting, but if I use readByte() 4 times and do some bit shifting and addition, I get -25198720, which is wrong. You may wonder ...

15. DataInputStream    coderanch.com

16. help me,about DataInputStream    coderanch.com

I want get database file from a server,server send me data content include: 200 ok(express file exit) FILESIZE 1496124(database file size) db file i want follow below is my code: public class getTar { private FileWriter os = null; /** * set filename * @param s * @return */ public boolean setFilename(String s) { try { File f1 = new File(s); ...





17. problem with DataInputStream    coderanch.com

hi all, We have this application based on client server architecture. Client and server are more or less symmetrical.Now the problem is code works fine when we run it on same machine but when we run client and server on two different machines program raises exception. File is transferred without any problem from client to server but when client tries to ...

18. problem with DataInputStream.readInt() method    coderanch.com

hi everyone, I have a slight problem.Im working with a client server pair on my own computer and just runing the server on this computer as well.On the client side i am trying to send an updated file to the server, then save that file on the servers drive (in this case my drive just another folder then where the client ...

19. DataInputStream with Runtime.getRuntime    coderanch.com

Hi All, I have this code: import java.io.*; public class TestExecProc { public static void main(String[] args) { try{ Process myProcess; myProcess = Runtime.getRuntime ().exec (new String [] {"cmd", "/c", "start", "mysql","-p1234","-u","root"}); String s = null; DataInputStream in = new DataInputStream(new BufferedInputStream(myProcess.getInputStream())); while ((s = in.readLine()) != null) { System.out.println(s); } } catch (Exception ex) { System.out.println(ex); } } } it ...

20. datainputstream.readInt problem    coderanch.com

Hi i have established socket connection using 80 port with the tomcat 5.0.28 from the client i am able to send dataoutputstream.writeInt(98). Server is able to receive the integer value 98. From serverSide i am sending dataoutputstream.write(93); i am not receive the integer value to the client. Please tell me what might be problem. ASAP Regards Nanaji

21. what is the diffrence between readUnsignedByte() and read() of DataInputStream    coderanch.com

readUnsignedByte, like all other methods specified by the DataInput interface, throws an EOFException if the end of the stream was reached. The method read doesn't throw an exception but returns -1. Both are required in DataInputStream because it is an InputStream that implements the DataInput interface (and thus must have both methods).

22. datainputstream.readInt() through a js file    coderanch.com

I have a jsp file which uses tag to load an applet. Now because of the Microsoft IE patch for ActiveX, i had to change my code.I took the entire code for tag into document.write in a function inside a js file. And i included that js file in my jsp file and called the function in place of ...

23. datainputstream and bufferedreader    coderanch.com

I am little confused about the new I/O streams. The Datainputstream has been notified to be deprecated (as it not handle the byte to character conversion properly - as told). Then what is the InputStream child to be used for byte(non-character) data? Also BufferedReader has been advised to be used for Datainputstream - But i believe thats for string data only.Is ...

24. Reading swedish characters thro DataInputStream    coderanch.com

Hi, My project basically deals with 3 platforms. One is the UI with Windows, the middle end with linux box and a server which is on VxWorks. i save a data with swedish character in the UI. We use Solid database to store the data. So i have introduced a CAST with WVARCHAR which can accept and store these characters. The ...

25. What is the difference between DataInputStream and BufferedReader?    coderanch.com

Hi, I am new to socket programming and learning the basics now. I have been seeing in sample programs that, the client gets the input from server socket thro DataInputStream at some places and through BufferedReader(wrapping the InputStreamReader) at some other places? What exactly differentiates the usage of the two classes here? What to use when? Please explain Shaik Muhammad

26. How to use FileReader with datainputstream    coderanch.com

Hi, I am trying to use the FileReader with the DataInputStream to read in characters from a text file (ex .4RDE.2CS.9WD ). I've never actually worked with files before, so I'm completely clueless on how to do it, or if it can be done the way I am trying to do it. I am using the '.' as a dilimiter, when ...

27. Problem using DataInputStream Class    coderanch.com

28. DataInputStream problem    coderanch.com

public static void main(String args[]) { try { // Create a data input stream DataInputStream dis = new DataInputStream(System.in); // Read and display data System.out.println("enter boolean"); Boolean b = dis.readBoolean(); System.out.println("you entered "+b); System.out.println("now enter a byte value"); byte b3 = dis.readByte(); System.out.println("you entered "+b3); // Close file input stream dis.close(); } catch (Exception e) { System.out.println("Exception: " + e); } ...

29. Read Bytes From DataInputStream    coderanch.com

Hi, I'm having an issue reading binary data over a socket. I'm using DataInputStream to read in the data and I'm able to print it out in Hex, but not in any kind of human readable format. Here is what I'm trying to read in and the code I'm using. I'm supposed to read in one byte with a value of ...

30. about DataInputStream class    coderanch.com

32. DataInputStream    coderanch.com

33. how to read integers using DataInputStream    coderanch.com

Without knowing what is in the file, it's impossible to say what you are doing wrong. But my guess is that your file contains some text which represents an integer, as opposed to 32 bits which represent an integer, and you were assuming that the readInt() method was meant for the first case instead of for the second case.

34. DataInputStream to file    java-forums.org

Java Code: import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; public class MainClass { public static void main(String args[]) throws Exception { URL u = new URL("http://www.java2s.com/binary.dat"); URLConnection uc = u.openConnection(); String contentType = uc.getContentType(); int contentLength = uc.getContentLength(); if (contentType.startsWith("text/") || contentLength == -1) { throw new IOException("This is not a binary file."); } InputStream raw ...

35. dataInputStream    forums.oracle.com

Hello Is it possible to store variable length byte[] and then simply retrieve them back? I have tried: ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); foo newFoo = new foo(); newFoo.setVal00("something"getBytes()); newFoo.setVal01("something a bit more".getBytes()); dos.write(newFoo.getVal00()); dos.write(newFoo.getVal01()); byte[] baOut00=baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(baOut00); foo newFoo2 = new foo(); DataInputStream dis = new DataInputStream(bais); dis.write(newFoo2.getVal00()); dis.write(newFoo2.getVal01()); ... System.out.println("Val00= ...

36. datainputstream, using readfully()    forums.oracle.com

37. DataInputStream    forums.oracle.com

38. datainputstream    forums.oracle.com

Hello I am having difficulty understanding how to read from a stream created with dataoutputstream in a nontrivial example. If I write a long, a byte[] of varying length, and two strings, I dont see how to read them back using the primitives readLong(), readFully(), readChar or readUTF, for data that was written with writeLong(), write(), writeChars(). I dont see any ...

39. datainputstream    forums.oracle.com

csckid wrote: New problem. I have a file of 34MB Is it possible to play the file which has been obtained by two inputstream.read()? and then play the next two inputstream.read() of the file. I was able to play the first two read. But when I try to play the next two read it says javax.microedition.media.MediaException: Malformed wave media You should ...

40. DataInputStream ...    forums.oracle.com

I am lucky that you are answering my question...............the statement i posted actually it was yours comment from one of my old post...... I was not clear at that time. Anyway, i liked the explantion. one thing i noticed that IF YOU use Datainputstream to write THEN YOU MUST/SHOULD use Datainputstream to READ also.....right ? anyway , i will look at ...

41. DataInputStream    forums.oracle.com

DataInputStream does that when you have reached the end of file! You should not use available(). It indicates how much data (in bytes not integers) can be read without the stream blocking and is allowed to be zero at any time. If you doubt me then read the Javadoc for InputStream. Either just read until the end-of-file is reached or work ...

43. Issues with DataInputStream even though File is OK?    forums.oracle.com

Thank you so much for your reply! I tried your suggestion and closed the istream after creating it, but then when I run the program, I still get an IOException when I try to write to the file, saying there is a null reference. Do I need to do anything special to open the istream back up again?

44. Help is needed in reading binary input from a file using DataInputStream    forums.oracle.com

I have not taken the time to study what you are doing but here is some thing to check. 1. print out ch1-4 and ensure that they have the values you expect. They might not if you are assuming an incorrect byte order. Off hand I don't know what byte order java uses, it's never been something I've had to concern ...

45. Positioning a DataInputStream    forums.oracle.com

You mean inside the object, given only the DataInputStream? No. DIS does not have to have any association to a file, and hence does not have any knowledge of the underlying file, if there is one. Now, if you mean "Can I create two independent DISes on one file?" then yes, you can.

46. DataInputStream,skipBytes    forums.oracle.com

47. DataInputStream    forums.oracle.com

50. Handling multiple DataInputStream EOFs    forums.oracle.com

kajbj wrote: So what do you expect the file that returns EOF to return if you continue reading from it? I don't want to keep reading a file once it returns eof, I want to continue reading the file that doesn't return eof. But like I'm reading the two on the same loop once one of these files ends the loop ...

51. how read a file part by part using DataInputStream    forums.oracle.com

So change the size of the buffer to the part-size you want to read in; read in a loop until the read() returns -1; and do whatever you have to do with the data inside the loop. Make sure you make use of the length returned by read() rather than assuming the buffer has been filled.

52. Wake up on DataInputStream.readInt()?    forums.oracle.com

Hi all, I am developing an application for two mobiles that communicate using Bluetooth. Communication is handled by a method containing several DataInputStream.readInt()'s. I noticed data missing because it is overwritten by either the method containing those readInts or events fired of by the users. I conclude I have a problem with accessing a shared resource. I can solve this problem ...

53. DataInputStream.read()    forums.oracle.com

Hi Im using the DatainputStream class to read segments of a specified file. Im trying to acheive this by passing in the following parameters to the read method, myDataInputStream.read(myByteArray[], 512, 512) Where my file in the datainputstream has a length of 31,000 (there abouts). The byte[] has a length of 512. My problem lies in the fact that the API states ...

54. DataInputStream & FileInputStream problem    forums.oracle.com

55. Possible to clear DataInputStream?    forums.oracle.com

I am using a PrintWriter for the 'out' variable and a BufferedReader for the 'in'. For the streams I use DataOut/InputStream. That doesn't sound good either; those DataStreams take care of binary data; those Readers/Writers take care of Unicode characters. Better keep socket based client/server communication as simple as possible, i.e. they both use streams or readers/writers and they both send ...