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
3
votes
3 answers

Why does usage of java.nio.files.File::list is causing this breadth-first file traversal program to crash with the "Too many open files" error?

Assumption: Streams are lazy, hence the following statement does not load the entire children of the directory referenced by the path into memory; instead it loads them one by one, and after each invocation of forEach, the directory referenced by p…
Behrang
  • 46,888
  • 25
  • 118
  • 160
3
votes
1 answer

how to create RandomAccessFile from InputStream?

The only way I know is to write a temp file, and read this file to create RandomAccessFile ,check it here or use Use Unified I/O library (http://uio.imagero.com) here Would this be the best way? Or can use temp file and the imageio library to…
Koerr
  • 15,215
  • 28
  • 78
  • 108
3
votes
2 answers

What actually happens when we open a connection to the file while creating a stream object?

Say when I write, InputStream inStream = new FileInputStream("LOCATION"); So what happens with the new FileInputStream("LOCATION") part? I read materials on the web stating it opens a connection to this location. So by "opening a connection"…
Mrudav Shukla
  • 708
  • 1
  • 7
  • 25
3
votes
1 answer

Java file copy does not work when the file is empty

In the code below, I am trying to copy the contents of src to dest and load dest to print the contents of it. If I have dest.txt available and it has some content in it, then I see that the contents gets overwritten and the contents gets printed…
serverfaces
  • 1,155
  • 4
  • 22
  • 49
3
votes
2 answers

Details of file.exists() in Java?

I'm using the following code to check if a file exists and can be read in Java: File sourceFile = new File(sourcePath); if (!sourceFile.exists() || !sourceFile.canRead()) throw new Exception("Source file is not accessible."); However, the issue…
Paul
  • 3,725
  • 12
  • 50
  • 86
3
votes
2 answers

Server not receiving input from client

I have a server and client. My problem is that when the client writes messages, the server is not receiving the messages. Server code public class BankServer { private int port; private BufferedReader reader = null; private…
MOR_SNOW
  • 787
  • 1
  • 5
  • 16
3
votes
2 answers

What is the use of CharArrayReader and StringReader?

I understand the other Reader subclasses in java.io, but I can't think of a use case where I'd need a CharArrayReader or a StringReader when I already have data available as String or char[]. Is it because of compatibility? To "feed" a String or…
ofalvai
  • 316
  • 6
  • 13
3
votes
4 answers

Error executing storm starter

I am trying to run the storm starter project locally. I am following the instructions from- https://github.com/apache/storm/tree/master/examples/storm-starter but when I try to execute the storm jar command, I get ERROR StatusLogger Invalid URL…
AbtPst
  • 7,778
  • 17
  • 91
  • 172
3
votes
1 answer

Why can't my system find my properties file?

I have a properties file called admin.properties under src/config and whenever I run the program it gives me this error: java.io.FileNotFoundException: admin.properties (The system cannot find the file specified) Here is my code: package…
haja
  • 135
  • 1
  • 4
  • 12
3
votes
1 answer

Writing byte array to an UTF8-encoded file

Given a byte array in UTF-8 encoding (as result of base64 decoding of a String) - what is please a correct way to write it to a file in UTF-8 encoding? Is the following source code (writing the array byte by byte) correct? OutputStreamWriter osw =…
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
3
votes
1 answer

Writing multiple images to byteArrayOutputstream

I've a requirement to add multiple images to a output stream and display those images in JSF. Ex code: List images = list of inputstream - each image is one input stream ByteArrayOutputStream stream = new…
TP_JAVA
  • 1,002
  • 5
  • 23
  • 49
3
votes
1 answer

Xpages SSJS - Outputting files is slow for large files

I am trying to output pdf files i have on the local filesystem of the domino server using instructions from Steve Wissel's page(s). http://www.wissel.net/blog/d6plinks/shwl-7mgfbn The file will get downloaded, but it takes a few minutes for files…
3
votes
1 answer

How to prevent the file to overwrite itself?

i've edited the code, can you please tell me how i can write each line at the end of the file? Here it's been written on the same line. Can you help please? private void okMouseClicked(java.awt.event.MouseEvent evt) { …
Lana
  • 171
  • 1
  • 7
  • 18
3
votes
1 answer

Editing a 1MB file continuously, what's more efficient?

I've to be continuously editing a 1MB file, simulating a file system. I've to modify the directory of File Control Blocks, FAT, blocks, etc. Proffesor recommended overwriting the file every time an update is made. 1MB shouldn't take minutes to do…
Carlos López-Camey
  • 2,504
  • 1
  • 17
  • 20
3
votes
2 answers

Write files using multiple threads

I need write many files in VM. I need write around 300.000 files, today work fine the job for generate files but the time used is 3~4 hours to finish job. How implement this parallel threads?
danillonc
  • 49
  • 1
  • 7