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
1
vote
3 answers

What's the proper way to continuously read socket messages through DataInputStream?

I'm trying to build a Java Bittorent client. From what I understand after peers handshake with one another they may start sending messages to each other, often sending messages sporadically. Using a DataInputStream connection I can read messages,…
Philip Rego
  • 552
  • 4
  • 20
  • 35
1
vote
2 answers

DataInputStream readInt() works only once

I'm using Java sockets to make two android devices communicating with the same app. The communication protocol is: 1. client sends packet size S 2. client sends byte array with size S I'm using DataOutputStream and writeInt() to write the size as…
eang
  • 1,615
  • 7
  • 21
  • 41
1
vote
2 answers

unable to input data to dataoutputstream

i'm creating a program that reads from file then change it to an arraylist of item and send it to to a client. A client chooses an item by id and enter amount needed. then it gets updated in the server. the server runs multithreading. when another…
1
vote
2 answers

Why I get java.io.FileNotFoundException in getting the response to my httpUrlConnection?

I don't know if Im sending my file right to web api. Because nothing gives an error to client request code. But when I'm getting the response to the server it gives me a java.io.FileNotFoundException. So I think that there's wrong in my request code…
1
vote
1 answer

ios slider data to java server using tcp socket

I am trying to make a simple server client program that allows me to send the slider value from an IOS client to a java server. I am stuck now because I am receiving data that I do not know how to handle. I am looking for a little guidance. I will…
1
vote
1 answer

Using BufferedReader and DataInputStream in harmony

I've been poking around the internet for quite a while now, and I was wondering how I could use BufferedReader and DataInputStream together without opening a different port. I've tried to stream images, but as the buffered reader stores extra bytes,…
Dylan Katz
  • 194
  • 2
  • 14
1
vote
1 answer

DataInputStream available() behaviour for reading files bigger than Integer.MAX_VALUE bytes

I have a binary file in custom format than I have written using DataOutputStream. The simplified format of the data in the file is: IntCharIntCharIntChar...IntChar I am using DataInputStream to read from this file, and available() to determine…
drnick
  • 13
  • 4
1
vote
1 answer

Equivalent of DataOutputStream and DataInputStream in C

I wrote this code in java public class Client { private static int _port; private static Socket _socket; public static void main(String[] args) { try { _port = 8071; _socket = new…
user2328999
  • 91
  • 3
  • 12
1
vote
2 answers

determining which client sent data using sockets

I have a problem. In my code i have an array of players, everyone with his "in" and "out" to the server. From Server to Clients i can communicate well and without any problem and every client shows in his GUI the change sent by Server. The problem…
auron344
  • 81
  • 1
  • 7
1
vote
0 answers

App crashes while send / receive ByteArray through socket

I'm trying to make a simple chatting app, using socket communication. My goal is to send and receive text and images(from smartphone gallery) successfully. Text part successful, but I'm having trouble with images. I wrote a code using…
mybalam2k
  • 11
  • 2
1
vote
3 answers

DataInputStream who close stream if IOException

In all examples everybody can find code like this: DataInputStream inputStream = null; try { inputStream = new DataInputStream( new FileInputStream("file.data")); int i = inputStream.readInt(); inputStream.close(); } catch…
Lesya Makhova
  • 1,340
  • 3
  • 14
  • 28
1
vote
4 answers

Read a definite number of lines in a text file, using java

I have a text file with data. The file has information from all months. Imagine that the information for January occupy 50 lines. Than February starts and it occupies 40 more lines. Than I have March and so on... Is it possible to read only part of…
greinodacosta
  • 43
  • 1
  • 7
1
vote
3 answers

How do I wait for data in file becomes available instead of getting EOFException

I'm displaying streaming content using a file to buffer it (because it could be large enough to keep it in RAM). I have two threads: the first downloads a file from server and writes it to the local storage, and the second reads that file and…
Grishka
  • 2,465
  • 1
  • 20
  • 38
1
vote
2 answers

deprecated readLine() What to change?

I'm a Java beginner, trying to get this to work in Eclipse. However, the readLine is struck through and a notice says it is deprecated. The code works, albeit not the while ((var2 = var5.readLine()) != null) { bit ... So I'm wondering how to fix…
NestedCodeblocksFTW
  • 716
  • 3
  • 11
  • 26
1
vote
1 answer

Java DataInputStream to image file

I am on an homework assignment where I have to connect to a http server and download html files and image files using socket programming. I am doing fine and is able to download and write both the html and image files correctly. But when I edit the…
jsoonnn
  • 11
  • 2