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
3
votes
1 answer

Java: Difference with dis.read() and dis.readUTF() in DataInputStream

Simple Question. What is Difference with dis.read() and dis.readUTF()? For example, dis.read() only read to byte array, and dis.readUTF() access String type. Is it correct? If Server has implements dis.readUTF(), it can not read byte…
reinhard.lee
  • 503
  • 4
  • 10
  • 24
3
votes
2 answers

Getting OptionalDataException because of primitive int value , but how to avoid it in JAVA

My Code- import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; public class…
Abhishek Choudhary
  • 8,255
  • 19
  • 69
  • 128
2
votes
1 answer

Android: DataInputStream & DataOutputstream not seeing my directory

I'm trying to save int values inside a text file on external storage. When I tried to use the saveAudio() function, I get a FileNotFoundException. What am I doing wrong? I'm running the program in an android emulator. File externalStorageDir = new…
iamarnold
  • 705
  • 1
  • 8
  • 22
2
votes
1 answer

DataInputStream.readInt() is causing high latency, am I doing this wrong?

Under here you find a simple server/client app that sends the integer 5 from the client to the server, which reads it and sends it back to the client. On the server I have placed a latency meter around the DataInputStream.readInt() method, which…
2
votes
1 answer

sending a file using DataOutputStream in java

I am trying to build a client that sends the file size and contents to server. I am trying to use DataOutputStream. I am assuming that I need to open the file and and get size of file and read the contents and send it. But I am not sure how to…
in His Steps
  • 3,075
  • 6
  • 30
  • 38
2
votes
1 answer

Reading "ls /datadata" output in loop

I'm developing a small application that has to read the contents of a protected folder, so I came to the conclusion that I had to use su in combination with ls and an inputstream. However, when the readLine function reaches the end of the output, it…
Quint Stoffers
  • 790
  • 8
  • 23
2
votes
2 answers

Pros and cons for using ObjectInputStream/ObjectOutputStream to implement network "packets" in Java?

I'm working on a simple client/server application that uses sockets for all the communications. Communications are packet-based and the concept of packets is implemented using a set of classes and ObjectInputStream/ObjectOutputStream wrapper for…
Andrey Agibalov
  • 7,624
  • 8
  • 66
  • 111
2
votes
1 answer

Reading hebrew from text file with Java

I'm having troubles with reading a UTF-8 encoded text file in Hebrew. I read all Hebrew characters successfully, except to two letters = 'מ' and 'א'. Here is how I read it: FileInputStream fstream = new…
tomericco
  • 1,544
  • 3
  • 19
  • 30
2
votes
0 answers

Read double value from TCP/IP connection Java

I need to read the double speed value of a driving simulator over tcp/ip. I tried it like this: Socket s = new Socket(server, port); InputStream is = s.getInputStream(); DataInputStream dis = new…
klipper
  • 21
  • 3
2
votes
2 answers

TextView remains the same it doesnt get set to any new value

I'm facing a problem,On a button press i try to read the DataInputstream which has data coming in and display the data. I'm using a while loop to read the data. But the dynamic update of the Textview doesnt happen. TextView datatextview =…
m4n07
  • 2,267
  • 12
  • 50
  • 65
2
votes
3 answers

Android: Reading from DataInputStream works in emulator but not on device

I am working on a simple AudioTrack example which reads in a PCM file then plays it back. It works great on the android emulator, but on my test phone it fails when reading in the data with the readShort() function. Here is where the code is…
JMartini
  • 31
  • 1
  • 4
2
votes
2 answers

Read an integer with DataInputStream in Java

I have this Java code: import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class DemoApp { public static void main(String args[]) { try…
elvis
  • 956
  • 9
  • 33
  • 56
2
votes
1 answer

PushBackInputStream and DataInputStream, how to push back a double?

If I want to read ahead a byte,and push it back if it is not '<',I can do it like this: PushbackInputStream pbin=new PushbackInputStream(new FileInputStream("1.dat")); int b = pbin.read(); if(b!='<') pbin.unread(b); But if I want to push back a…
2
votes
1 answer

Swift converting a byte array to integers

Hello I am new to swift and would like to convert a byte array to several integers. I have written working code in Java but I am not quite sure how to take it to swift byte[] codeData = Base64.decode(codeDataBase64, 0); ByteArrayInputStream…
Alec
  • 666
  • 8
  • 23
2
votes
0 answers

Xuggler not reading file from ByteArrayInputStream if filesize is greater that 7 MB

I am new to Xuggler. I want to write a program which reads a video file from ByteArrayInputStream. This is the code: public static String path="/home/gurinderbeer/Downloads/IMG_1579.MOV"; public static void main(String[] args) throws…
1 2
3
22 23