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

Java DataOutputStream doesn't throw IOException on disconnect

DataOutputStream doesn't throw an IOException when I plug my cable out, what's wrong with my code? Here is my code: private void sendMessage(String message) { try { mDataOutputStream.writeUTF(message); mDataOutputStream.flush(); …
Jeremy
  • 113
  • 7
0
votes
2 answers

What is the difference between DataOutputStream and printwriter?

What is the difference between DataOutputStream and printwriter?
Kanaiya Katarmal
  • 5,974
  • 4
  • 30
  • 56
0
votes
2 answers

Confusion about DataOutputStream

I wrote the code below to familiarise myself with DataOutputStream. I suppose there would be some kind of 11010111 binary in the file where I output the data, instead, there are just some readable strings. My question is: shouldn't there be binary…
glenlivet1986
  • 260
  • 3
  • 12
0
votes
2 answers

Reading/writing a BINARY File with Strings?

How can I write/read a string from a binary file? I've tried using writeUTF / readUTF (DataOutputStream/DataInputStream) but it was too much of a hassle. Thanks.
Bob Let
  • 123
  • 1
  • 5
  • 13
0
votes
3 answers

Is there any way to send an array of Point with DataOutputStream over a Socket?

I want to send an array of point (Point points[] = new point[20]) with DataOutputStream over a socket and be able to correctly read it with DataInputStream on the other side. I CANNOT send each element separately, it must be sent as a whole array…
KeatonB
  • 213
  • 2
  • 10
-1
votes
2 answers

How can I write 7 byte Integer value to DataOutputStream, which contains 15 digits?

I have to write 7 byte Integer value to DataOutputStream, this Integer contains 15 digits. How can I do that?
Gonzo
  • 21
  • 5
-1
votes
1 answer

How do I convert byte data into an image format that's usable within Java?

I'm currently making a Java application to take an image from a fingerprint scanner (ZK4500 model) and display it on the screen. The SDK code is pretty straight forward and I have everything working from the user's perspective. However, the only…
-1
votes
1 answer

Confusion around how byte array writing works in Java

Let’s say I have a huge set of strings that I want to write into a file as efficient as possible. I don’t care if it’s not human readable. The first thing that came to my mind was to write the string as raw bytes to a binary file. I tried using…
Corner
  • 29
  • 1
  • 2
  • 11
-1
votes
1 answer

Why I cannot use my DataOutputStream Twice?

I've tried to send a message to my server twice, but It keeps having an error. I wonder what I should do to make this thing work. I keep having an error on this line "msgToServer.witeBytes("GETACCESS"+jTextFieldUsername.getText()+"…
Odain
  • 1
  • 2
-1
votes
1 answer

nullPointerException while using DataInputStream and DataOutputStream to send and int

I'm practicing on a simple Client / Server connection. The client is supposed to send an Int to the server, and the server is supposed to print this int. However, the server encounters a NullPointerException and doesn't print the int sent by the…
-1
votes
1 answer

How to write a 2D array of floats in a file as bytes?

I have the following float array: float[] arr = [ (1.2,2.3,2.4), (4.7,4.8,9.8) ] and I wish to write it on a file through DataOutputStream in bytes. I have tried this so far: DataOutputStream out = new DataOutputStream(new…
hispanicprogrammer
  • 367
  • 3
  • 6
  • 22
-1
votes
1 answer

How can I send an image from java socket Server to a navigator wihtout being corrupted?

I am trying to code a java socket server to send an image from this server to the navigator(client side). But when I send the image the file seen to be corrupted (display the image with symbols). DataOutputStream dout = new…
daiboss
  • 7
  • 2
-1
votes
1 answer

Looping DataOutputStream writeUTF in thread

I'm trying to loop the writeUTF function in a thread and it only runs once despite it being in a while loop. The purpose is to loop through a large byte[] and send it in packets and i'm stuck on writeUTF only running once. I tried a for loop with…
Billy
  • 1
  • 1
-1
votes
1 answer

Write data from datainputstream to a file in Java

I am learning about socket programming in Java from the below link: https://www.geeksforgeeks.org/socket-programming-in-java/ The code for server from the tutorial is as follows(I have added extra lines to copy in a file): // A Java program for a…
Lax_Sam
  • 1,099
  • 2
  • 14
  • 32
-1
votes
1 answer

Resuming a file upload in java Socket

package experiments; import java.io.*; import java.net.Socket; /** * * @author User */ /*THE CLIENT*/ public class UploadManager { public static void setup(String address, int port,String path){ try( Socket s = new Socket(address,port);…
aloy
  • 53
  • 6