Questions tagged [datainputstream]

A DataInputStream lets an application read primitive Java data types from an underlying input stream in a machine-independent way.

The DataInputStream class enables you to read Java primitives from InputStream's instead of only bytes. Wrap an InputStream in a DataInputStream and then you can read primitives from it. DataInputStreams represent Unicode strings in a format that is a slight modification of UTF-8.

339 questions
82
votes
4 answers

Close multiple resources with AutoCloseable (try-with-resources)

I know that the resource you pass with a try, will be closed automatically if the resource has AutoCloseable implemented. So far so good. But what do I do when i have several resources that I want automatically closed. Example with sockets; try…
asmb
  • 1,015
  • 2
  • 8
  • 11
35
votes
4 answers

DataInputStream deprecated readLine() method

I am on java 6. Using DataInputStream in = new DataInputStream(System.in); to read user input. When the readLine() is deprecated. What is the work around for reading user value? DataInputStream in = new DataInputStream(System.in); int num; try { …
Some Java Guy
  • 4,992
  • 19
  • 71
  • 108
9
votes
4 answers

Reading Integer user input in DataInputStream in java?

I am trying to get input from user using DataInputStream. But this displays some junk integer value instead of the given value. Here is the code: import java.io.*; public class Sequence { public static void main(String[] args) throws IOException…
harvish
  • 195
  • 1
  • 4
  • 11
9
votes
2 answers

Interrupting Java DataInputStream readFully()

I have a Java applet that streams video (MJPEG) from a server. I wrote a proxy server in C# (Windows service) to put between the applet and multiple video servers. A HTML/CSS/Js frontend is used along with the Java applet. All functionality works…
mittmemo
  • 2,062
  • 3
  • 20
  • 27
8
votes
5 answers

DataInputStream.read returning less than len

I am using DataInputStream to read some bytes from a socket. I have a expected number of bytes to read from the stream (after decoding a header, I know how many bytes are in the message) It works 99% of the time but occasionally I will have the…
barab157
  • 111
  • 1
  • 4
7
votes
6 answers

DataInputStream vs InputStreamReader, trying to conceptually understand the two

As I tentatively understand it at the moment: DataInputStream is an InputStream subclass, hence it reads and writes bytes. If you are reading bytes and you know they are all going to be ints or some other primitive data type, then you can read those…
ross studtman
  • 936
  • 1
  • 8
  • 22
6
votes
4 answers

Unknown buffer size to be read from a DataInputStream in java

I have the following statement: DataInputStream is = new DataInputStream(process.getInputStream()); I would like to print the contents of this input stream but I dont know the size of this stream. How should I read this stream and print it?
nikhil
  • 9,023
  • 22
  • 55
  • 81
6
votes
5 answers

Need for Data Input Stream

What is the difference between FileInputStream fstream = new FileInputStream ("file1.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); and FileInputStream fstream = new FileInputStream…
Arun A K
  • 2,205
  • 2
  • 27
  • 45
6
votes
3 answers

Is there a class that exposes an unbuffered readLine method in Java?

I'm cleaning up some chunks of our codebase at work, and one of the older classes is used to read and write data. This data is a mixture of US-ASCII encoded Strings and binary encoded primitives. The current implementation uses DataInputStream, but…
Doug Stephen
  • 7,181
  • 1
  • 38
  • 46
5
votes
3 answers

Difference Between DataInputStream/DataOutputStream Class & InputStream/OutputStream Class

Whenever I use HttpConnection Class in Java ME, Android or in BlackBerry, I uses DataInputStream/DataOutputStream class for reading & writing datas over remote server. However there are other class like InputStream/OutputStream which can be use for…
Lucifer
  • 29,392
  • 25
  • 90
  • 143
5
votes
3 answers

Check if DataInputStream has content

Is there a way to ask a DataInputStream, if it has content to read? .readByte() will just hang it, waiting for a byte to be read :( Or do I always have to send a Dummy-Byte, to make sure it always sees something?
Pwnie2012
  • 143
  • 1
  • 7
4
votes
2 answers

DataInputStream class Equivalent in C#

I want to know what is the Java DataInputStream class equivalent in C#
saikamesh
  • 4,569
  • 11
  • 53
  • 93
4
votes
2 answers

fwrite() in C & readInt() in Java differ in endianess

Native Code : writing number 27 using fwrite(). int main() { int a = 27; FILE *fp; fp = fopen("/data/tmp.log", "w"); if (!fp) return -errno; fwrite(&a, 4, 1, fp); fclose(); return 0; } Reading back the data(27) using…
Sandeep
  • 18,356
  • 16
  • 68
  • 108
4
votes
4 answers

How to remove first 4 bytes from a byte array in Java?

I have a byte array named byteArr[].I need to remove first 4 bytes from it.My code is shown below. Here I use the byte array to store the input string.I got some unwanted byte with the output i.e the first four bytes is not needed from the fifth…
Miller
  • 744
  • 3
  • 15
  • 39
4
votes
2 answers

System.out in DataOutputStream is not printing on the console

I am trying the following code using the DataOutputStream. The OutputStream passed to the DataOutputStream is not printing anything. Please see my below code and pllease tell me anything wrong in this code. public class DataStreamsExample { public…
Sivaranjani D
  • 512
  • 4
  • 16
1
2 3
22 23