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

Write bytes into a file without erasing existing bytes

Possible Duplicate: Best Way to Write Bytes in the Middle of a File in Java I have a file in which I need to write bytes. I know at which position in the file I need to insert specific bytes. To make things clear, I need to write bytes in the…
Jean Logeart
  • 52,687
  • 11
  • 83
  • 118
9
votes
4 answers

Basics - reading/writing remote files using Java

I started with requirement of reading and writing files in from/in a directory on a remote Ubuntu machine. First, I wrote a Java program that could read,write files from a shared folder on a remote Windows machine i.e on a LAN. Here, something like…
Kaliyug Antagonist
  • 3,512
  • 9
  • 51
  • 103
9
votes
4 answers

Process Builder waitFor() issue and Open file limitations

I have inherited some code: Process p = new ProcessBuilder("/bin/chmod", "777", path).start(); p.waitFor(); Basically, there is for some ancient and highly voodoo based reason for storing key/value pairs on disk as files. I don't really want to go…
lsl
  • 4,371
  • 3
  • 39
  • 54
8
votes
5 answers

How to create an InputStream from an array of strings

I have an array of strings ( actually it's an ArrayList ) and I would like to create an InputStream from it, each element of the array being a line in the stream. How can I do this in the easiest and most efficient way?
Zoltán Szőcs
  • 1,141
  • 2
  • 11
  • 23
8
votes
7 answers

Getting meaningful text from Java.io.Reader

I have a program that I'm writing where I am using another company's library to download some reports from their website. I want to parse these reports before I write them to a file, because if they match certain criteria, I want to disregard them.…
Tom
  • 911
  • 4
  • 10
  • 21
8
votes
6 answers

Custom implementation of InputStream

To send data to a file on my FTP server, I need to create a custom InputStream implementation that reads database data row by row, converts it to CSV and publishes it via its read() methods: from the database, I get a List object with…
John Manak
  • 13,328
  • 29
  • 78
  • 119
8
votes
1 answer

Sonar: How to use try-with-resources to close FileOutputStream

Sonar is giving an error that this FileOutputStream should be closed. I need to modify the following code to use try-with-resources. How do I do this? public void archivingTheFile(String zipFile){ byte[] buffer = new byte[1024]; try{ …
user1921479
  • 255
  • 2
  • 6
  • 13
8
votes
1 answer

Random access file FileLock: java.io vs. java.nio

I've noticed that java.io and java.nio implementations of random access files differ slightly with respect to how FileLocks are handled. It appears as though (on Windows) java.io gives you a mandatory file lock and java.nio gives you an advisory…
predi
  • 5,528
  • 32
  • 60
8
votes
1 answer

Java deleteOnExit and addShutdownHook - which comes first?

I have a number of temporary files that I call deleteOnExit() on. I also have a runnable that I register with addShutdownHook() to run when System.exit is called. Is there any guarantee that the temporary files will still be available when my…
Klitos Kyriacou
  • 10,634
  • 2
  • 38
  • 70
8
votes
4 answers

Why both Files.exists(…) and Files.notExists(…)?

IMO having both of these methods is redundant and really unclear! i can't quite understand why both of these methods are designed in Files API ?? Files.exist(..) returns true if file really exist and false if not exist or not having permission. so…
Morteza Adi
  • 2,413
  • 2
  • 22
  • 37
8
votes
5 answers

java.io.FileNotFoundException on an existing file

I am getting this error when I try to open a file: java.io.FileNotFoundException: D:\Portable%20Programs\Android%20Development\workspace3\XXX-desktop\bin\World_X.fr (The system cannot find the path specified) at…
Rafay
  • 6,108
  • 11
  • 51
  • 71
8
votes
5 answers

How to pipe InputStream to ProcessBuilder

Please move down to the 2nd update. I didn't want to change the previous context of this question. I'm using wkhtmltoimage from a Java app. The standard way of using it is - path-to-exe http://url.com/ image.png. According to their docs, if we write…
Hrishikesh Choudhari
  • 11,617
  • 18
  • 61
  • 74
8
votes
2 answers

FileNotFoundException (no such file or directory)

I'm writing an android app and I need to read several files from several folders and add them to several zip archives. I need to limit the max size of the archives to lets say 16mb. So at runtime while adding the files to the archive if the size of…
androidu
  • 4,678
  • 6
  • 36
  • 51
8
votes
4 answers

REST CXF and Spring cxf-extension-jaxrs-binding File not found exception?

i'm trynig to develop a REST web service using CXF 2.6.0 and spring 2.5.6 my CXF maven dependancy in the pom.xml are : org.apache.cxf cxf-rt-rs-extension-providers
Moezgadjo
  • 81
  • 1
  • 1
  • 5
7
votes
4 answers

Why cant a RandomAccessFile be casted to Inputstream?

I get compilation error when I do this cast: RandomAccessFile raf = new RandomAccessFile(...) InputStream is = (InputStream)raf; RandomAccessFile is supposed to subclass InputStream although not directly. From docs: RandomAccessFile implements…
PS1
  • 125
  • 1
  • 1
  • 6