Questions tagged [java-io]

The java.io package provides blocking input and output through data streams, serialization, and the file system.

Most applications need to process some input and produce some output based on that input. The purpose of the Java IO package (java.io) is to make that possible in Java.

The java.io package provides blocking input and output through data streams, serialization and the file system.

1753 questions
7
votes
2 answers

Read/Write Bytes to and From a File Using Only Java.IO

How can we write a byte array to a file (and read it back from that file) in Java? Yes, we all know there are already lots of questions like that, but they get very messy and subjective due to the fact that there are so many ways to accomplish this…
Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100
7
votes
7 answers

Java read file got a leading BOM [  ]

I am reading a file containing keywords line by line and found a strange problem. I hope lines that following each other if their contents are the same, they should be handled only once. Like sony sony only the first one is getting processed. but…
Sawyer
  • 15,581
  • 27
  • 88
  • 124
7
votes
0 answers

read file from jar in spring-boot

I am using Spring boot 2.0.4, trying read a json file which is placed in resources/ directory, but getting the 'FileNotFoundException'. I have referred a lot of pages from Stackoverflow, and other links, but no success so far. Following is the…
Nitin1706
  • 621
  • 1
  • 11
  • 21
7
votes
2 answers

Testing for empty InputStream in Java

how do you guys test for an empty InputStream? I know that InputStream is designed to work with remote resources, so you can't know if it's there until you actually read from it. I cannot use read() because current position would change and using…
lisak
  • 21,611
  • 40
  • 152
  • 243
7
votes
1 answer

How copy files bigger than 4.3 GB in java

I'm writing a program part simply to copy a file from source to a destination File. The code works as well it should but if there is a file large file the process of copy will end up, after the destination file reach a size of 4.3 GB, with an…
7
votes
3 answers

java.io.File.(File,String) JDK version dependent

It's looks like java.io.File.(File, String) is JDK version dependent. Code example was run on Windows 10. Code example: public static void main(String... args) { String path = "C:\\Workspace\\project"; File file = null; for (String part…
Ivan Kalinin
  • 215
  • 1
  • 10
7
votes
4 answers

Android: How to store data on internal memory?

It's perfectly described here how to do it, the only problem: He doesnt know the function openFileOutput(); private void saveSettingsFile() { String FILENAME = "settings"; String string = "hello world!"; …
OneWorld
  • 17,512
  • 21
  • 86
  • 136
7
votes
1 answer

Why you can read data from already closed ByteArrayOutputStream?

I'm wondering why you still can read bytes from already closed ByteArrayOutputStream. Doesn't this line from docs mean the opposite? public void close (): Closes this stream. This releases system resources used for this stream. Sample code:…
Roman
  • 898
  • 1
  • 10
  • 24
7
votes
3 answers

Socket server that waits for message from client to read

I have the following socket server in java, import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; public class MiddleSocket { …
jgr208
  • 2,896
  • 9
  • 36
  • 64
7
votes
1 answer

Performance drop upgrading from Hazelcast 2.5 to 3+

Because of a known (fixed) bug in Hazelcast 2.5 we've decided this would be the next upgrade candidate for our project. But after dropping in the latest version (3.2.2) we had horrible performance. The way we are using Hazelcast: Two nodes Multiple…
Roy van Rijn
  • 840
  • 7
  • 17
7
votes
3 answers

Java ImageIO.write return false

I want to save a BufferedImage (named "result"): boolean bres = ImageIO.write(result, ".png", new File(saveP)); But bres is always null. This ImageIO.getWriterFormatNames() returns that: jpg BMP bmp JPG jpeg wbmp png JPEG PNG WBMP GIF gif I…
user3363881
  • 101
  • 1
  • 5
7
votes
3 answers

Read file and write file which has characters in UTF - 8 (different language)

I have a file which has characters like: " Joh 1:1 ஆதியிலே வார்த்தை இருந்தது, அந்த வார்த்தை தேவனிடத்திலிருந்தது, அந்த வார்த்தை தேவனாயிருந்தது. " www.unicode.org/charts/PDF/U0B80.pdf‎ When I use the following code: bufferedWriter = new…
Alfa
  • 599
  • 6
  • 22
7
votes
3 answers

Java Transformer outputs < and > instead of <>

I am editing an XML file in Java with a Transformer by adding more nodes. The old XML code is unchanged but the new XML nodes have < and > instead of <> and are on the same line. How do I get <> instead of < and > and how do I get line…
RegedUser00x
  • 2,313
  • 5
  • 27
  • 34
7
votes
4 answers

Reading error stream from a process

I am writing a java program to read the error stream from a process . Below is the structure of my code -- ProcessBuilder probuilder = new ProcessBuilder( command ); Process process = probuilder.start(); InputStream error =…
user496934
  • 3,822
  • 10
  • 45
  • 64
6
votes
2 answers

How to Read files in an folder inputstream

I have a Jar file that I have created using 3rd party library. When I packaged the jar file, I am including several xml files inside it in a folder named data data - file1.xml - file2.xml - file3.xml Now, I wanted to read the folder…
Mark Estrada
  • 9,013
  • 37
  • 119
  • 186