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

DataOutputStream#writeBytes(String) vs BufferedWriter#write(String)

I would like to create a HTML file for my report. The content in the report can be created either by using BufferedWriter#write(String) File f = new File("source.htm"); BufferedWriter bw = new BufferedWriter(new…
Java Beginner
  • 1,635
  • 11
  • 29
  • 51
6
votes
8 answers

About File file = new File(path)

The Java.iO.File document says the following words about its constructor which takes the pathname: public File(String pathname) Creates a new File instance by converting the given pathname string into an abstract pathname. If the given…
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
6
votes
5 answers

Can apache FileUtils.writeLines() be made to append to a file if it exists

The commons FileUtils look pretty cool, and I can't believe that they cannot be made to append to a file. File file = new File(path); FileUtils.writeLines(file, printStats(new DateTime(), headerRequired)); The above just replaces the contents of…
Ben
  • 1,106
  • 1
  • 9
  • 17
6
votes
2 answers

Making sure file gets deleted on JVM exit

Does File.deleteOnExit() guarantee that the file is deleted even if the JVM is killed prematurely?
Hamza Yerlikaya
  • 49,047
  • 44
  • 147
  • 241
6
votes
4 answers

Java, the fastest class to read from a txt file

I have to read txt files in my program. Im currently using FileReader and BufferedReader. I tried to use Scanner but its slower than FileReader and BufferedReader. Is there any class, which can read files faster ? It must be written in Java…
user1736332
  • 693
  • 4
  • 11
  • 22
6
votes
3 answers

ClassCastException when Appending Object OutputStream

I have been trying to do a little project that needs an appendable ObjectOutputStream. I have gone through a couple of solutions and i found this It seemed to solve my problem at first. But on further development of my project i started getting…
sasidhar
  • 7,523
  • 15
  • 49
  • 75
6
votes
1 answer

JDK 7 WatchService API and NFS file sharing

We are using [WatchService][1] API (JDK 7) to track files created in my system. And up till now, it worked ok. Every file created on my system tracked by my program. But we have trouble when we use NFS (the directory we track actually exist on…
tnk_peka
  • 1,525
  • 2
  • 15
  • 25
5
votes
2 answers

Cannot implicitly convert type 'System.IO.Stream' to 'Java.IO.InputStream'

I referred some similar questions on SO but none of them deals with IO. I had used the same code in java when I used Eclipse. That time it worked. But now I try to use this code in Mono for Android (C#), it doesn't work. I'm trying to run this code…
GAMA
  • 5,958
  • 14
  • 79
  • 126
5
votes
3 answers

Deleting files in Android

I have a directory that contains a lot of files. I want to delete the entire directory as well as all the files in it. I want my code to wait until every File in that directory (including the directory itself) is deleted before the next command is…
Fresher
  • 269
  • 5
  • 16
5
votes
2 answers

Java - Object Stream efficiency over network

Quick design question: I need to implement a form of communication between a client-server network in my game-engine architecture in order to send events between one another. I had opted to create event objects and as such, I was wondering how…
WATWF
  • 65
  • 1
  • 5
5
votes
3 answers

Thread.interrupt() and java.io.InterruptedIOException

I'm running Java 1.5 on Solaris 10. My program is a standalone java program, using java concurrency package and log4j-1.2.12.jar to log certain information. primary logic is as below ExecutorService executor = new AppThreadPoolExecutor(10, 10, 0L,…
huahua
  • 285
  • 2
  • 5
  • 17
5
votes
2 answers

How can I write to stdout using FlatFileItemWriter in spring batch?

I have the following writer configured in my beans definition file of a spring batch project :
Philippe
  • 6,703
  • 3
  • 30
  • 50
5
votes
3 answers

reduce number of opened files in java code

Hi I have some code that uses block RandomAccessFile file = new RandomAccessFile("some file", "rw"); FileChannel channel = file.getChannel(); // some code String line = "some data"; ByteBuffer buf =…
ykhrustalev
  • 604
  • 10
  • 18
5
votes
3 answers

Limit method calls per second(s) (refuse when limit reached)

I have a method that does some IO, and I'd like to limit the calls (per second) to this method to avoid the backend to get bursts of concurrent requests it can't handle. If the requirement came without the "per second" I could just use a stack…
AndrewBourgeois
  • 2,634
  • 7
  • 41
  • 58
5
votes
0 answers

Update symlink without deletion in java

I was wondering is there any way to update the symlink target without delete the old symlink. I have two pieces of code, which happens at same time. The first piece is downloading some data every hour and store it in /some/directory, and it will…
Peter Ju
  • 51
  • 2