Questions tagged [dataoutputstream]

A mechanism for writing abstract data to a stream

A DataOutputStream is a mechanism for writing any abstract data to a stream, regardless of the type of the data. A stream is usually comprised of data to write to a local file, or data being transmitted to a remote server over a network protocol such as HTTP or FTP.

An DataOutputStream is abstract, and doesn't describe the type of data that is being written. Typically, if you are able to, you would implement one of the subclasses instead, such as FileOutputStream, which more appropriately describes the type of data being handled, and provides additional methods appropriate for that data type.

257 questions
-1
votes
1 answer

Is Java's DataInputStream's readByte() faster than readInt()?

Background: I'm currently creating an application in which two Java programs communicate over a network using a DataInputStream and DataOutputStream. Before every communication, I'd like to send an indication of what type of data is being sent, so…
-1
votes
1 answer

Server Socket reads Client message indefinitely in Java

In my simple Java Client-Server program, when sending a message to the server and reading it there, readInt() reads indefinitely, making the program stick there. I made sure I was only sending and receiving an int, nothing else, as you can tell by…
-1
votes
2 answers

why DataOutputStream is preferred in Server Client program

Why DataInputStream/DataOutputStream is used or preferred over any other stream of java like BufferedInputStream/BufferedOutputStream , BufferedReader/BufferedWriter in Socket programming like Server Client program ? Please explain the difference…
-1
votes
1 answer

Java - DataOutputStream writeLong\Byte\Double\Int Speed

I implemented a way to write primitive Java types to a binary output file using DataOutputStream's writeX methods, but I'm observing 60-fold slower performance relative to a previous implementation that writes to a text file via a BufferedWriter. I…
Sean
  • 1,283
  • 9
  • 27
  • 43
-1
votes
2 answers

write int from Java client to c server over socket

I thought it might be byte ordering but it doesn't look like it. I am not sure what else it could be. Java client on linux private static final int CODE = 0; Socket socket = new Socket("10.10.10.10", 50505); DataOutputStream output = new…
Nicolas
  • 331
  • 4
  • 13
-1
votes
2 answers

How to read and write integer -1 into DataOutputStream

I want to read and write some values into the DataOutputStream, but sometimes the value is int -1. I am able to write this value but while reading getting EOFException, I think the value -1 its reading a EOF. Can someone help me to figure out how…
AndroidDev
  • 888
  • 3
  • 13
  • 27
-1
votes
1 answer

Why do I get a ClassCastException when trying to cast stream from socket?

I am trying to establish a bluetooth connection between my Android app (the client) and my python server. However, I have got a problem with the streams. This piece of code throws a ClassCastException and I don't know why and how to fix it. Any…
user2426316
  • 7,131
  • 20
  • 52
  • 83
-1
votes
1 answer

writing files / large amount of bytes fails

I am writing files / large amount of bytes over socket. But lets say I am writing bytes. I do this; //Connection.data is a dataoutputstream byte[] a = new byte[filelength]; //load file into the array //write file for (int i = 0; i < a.length; i++)…
-1
votes
1 answer

Cannot read a byte array from socket

i am writing an application where i transfer a byte array over a socket in java. The generation of byte array at the client end is as follows: String vote = br.readLine(); // the data that i now encrypt using RSA PublicKey pubKey =…
Amit Vig
  • 175
  • 2
  • 12
-2
votes
1 answer

How to write to a dummy DataOutputStream without using files?

I'm using a specific library (unfortunately can't be avoided) that writes some information from a class to a file using a utility function that receives a DataOutputStream as the input. I would like to get the resulting file's content as a String…
DMan16
  • 3
  • 1
-2
votes
1 answer

DataOutputStream is not working the second time

I wan to write a message to a server. The first time I send a message everything works fine. But the second time I want to send another command the dos.writeUTF(message); line is throwing the NullPointerException. I really don't know…
-2
votes
1 answer

How to send a valid result of an arithmetic operation through DataOutputStream

I have a subprocess class that calculate the sum of two integers and then put it in a DataOutputStream: public class SubProcess { public static void main(String[] args) throws IOException { DataInputStream in = new…
Moh Lamine
  • 72
  • 1
  • 9
-2
votes
1 answer

Null point-er exception in Java

I am having a weird problem in this code. When I execute the code with the first if condition, it all works fine and as expected. However, when I comment that if statement and use the other if condition (the one already commented), it gives an…
T-D
  • 373
  • 8
  • 21
-3
votes
1 answer

DataOutputStream writeObject compilation error

I need help writing an object to a file in Java with this code. FileOutputStream objectFOS = new FileOutputStream("Items.dat"); DataOutputStream objectDOS = new DataOutputStream(objectFOS); objectDOS.writeObject(one); one is of class Item that I…
Gideon
  • 37
  • 1
  • 9
-3
votes
4 answers

Merge Two text files line by line using java

First text file A.txt; asdfghjklqw12345 qwe3456789 asdfghjklqw12345 qwe3456789 Second text file B.txt; |Record 1: Rejected - Error on table AUTHORIZATION_TBL, column AUTH_DATE.ORA-01843: not a valid month| |Record…
Avisek Panda
  • 19
  • 1
  • 1
  • 2
1 2 3
17
18