Questions tagged [apache-commons-io]

Apache Commons IO is a library of utilities to assist with developing IO functionality.

Apache Commons Commons IO is a library of utilities to assist with developing IO functionality.

There are six main areas included:

  • Utility classes - with static methods to perform common tasks
  • Input - useful Input Stream and Reader implementations
  • Output - useful Output Stream and Writer implementations
  • Filters - various implementations of file filters
  • Comparators - various implementations of java.util.Comparator for files
  • File Monitor - a component for monitoring file system events

Official Website: http://commons.apache.org/io/

Useful Links:

Related Tags:

187 questions
255
votes
11 answers

Delete all files in directory (but not directory) - one liner solution

I want to delete all files inside ABC directory. When I tried with FileUtils.deleteDirectory(new File("C:/test/ABC/")); it also deletes folder ABC. Is there a one liner solution where I can delete files inside directory but not directory?
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
41
votes
4 answers

Is it safe to use Apache commons-io IOUtils.closeQuietly?

Is this code BufferedWriter bw = new BufferedWriter(new FileWriter("test.txt")); try { bw.write("test"); } finally { IOUtils.closeQuietly(bw); } safe or not? As far as I understand when we close a BufferedWriter it…
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
40
votes
2 answers

Do I need to close the input stream manually after using IOUtils.toString(input) of commons-io?

Commons-IO has an IOUtils.toString(inputStream) method, which can read all content from an input stream: InputStream input = getInputStream(); String content = IOUtils.toString(input); My question is shall I close the input stream manually after…
Freewind
  • 193,756
  • 157
  • 432
  • 708
21
votes
9 answers

Reading a specific line from a text file in Java

Is there any method to read a specific line from a text file ? In the API or Apache Commons. Something like : String readLine(File file, int lineNumber) I agree it's trivial to implement, but it's not very efficient specially if the file is very…
Lluis Martinez
  • 1,963
  • 8
  • 28
  • 42
18
votes
6 answers

Recursively finding only directories with FileUtils.listFiles

I want to collect a list of all files under a directory, in particular including subdirectories. I like not doing things myself, so I'm using FileUtils.listFiles from Apache Commons IO. So I have something like: import java.io.File; import…
Dave B
  • 1,091
  • 2
  • 8
  • 5
17
votes
2 answers

Apache Commons IO Tailer example

I am working on a monitoring program that reads the /var/log/auth.log file. I am using Apache Commons IO Tailer class to read the file in real time. To get started, I wanted to test the real-time reading part on a simple file, and manually enter…
user2435860
  • 778
  • 3
  • 9
  • 22
14
votes
2 answers

Problems deleting a file with Java (apache commons io)

I am calling a C++ Method via JNI which creates two files. A text log file and a pdf file in a given directory. I want to delete these files (if they exist) before executing the JNI method. I am using Apache commons.io (FileUtils.forceDelete(File…
user212926
13
votes
2 answers

Download file using java apache commons?

How can I use the library to download a file and print out bytes saved? I tried using import static org.apache.commons.io.FileUtils.copyURLToFile; public static void Download() { URL dl = null; File fl = null; try { …
Kyle
  • 3,004
  • 15
  • 52
  • 79
11
votes
1 answer

Duplicated files copied in APK when including both Joda Time and Common IO libraries in Android project

I have an Android project (Gradle) where I need to include both Joda Time and Commons IO libraries. This is my Gradle file: apply plugin: 'android-library' apply plugin: 'android-test' buildscript { repositories { mavenCentral() } …
Juan Herrero Diaz
  • 833
  • 1
  • 7
  • 17
9
votes
1 answer

FileUtils.copyUrlToFile is not working

I have fairly basic question i'm trying to download a PDF from this URL using java:…
Gideon Oduro
  • 200
  • 1
  • 2
  • 15
8
votes
6 answers

Android Studio3.2 APK Build Error -> reserved file or directory name 'lib'

Android Studio Version 3.2 (AI-181.5540.7.32.5014246). In Android Studio 3.1, I was able to build SignedAPK successfully. But as soon as I made Android Studio 3.2, I could not build a SignedAPK at all. What is the cause of this problem? I have not…
user3323951
  • 397
  • 3
  • 10
8
votes
2 answers

Why is ReversedLinesFileReader so slow?

I have a file that is 21.6GB and I want to read it from the end to the start rather than from the beginning to the end as you would usually do. If I read each line of the file from the start to the end using the following code, then it takes 1…
Arthur
  • 1,332
  • 2
  • 19
  • 39
8
votes
2 answers

Should I close the InputStream of org.apache.commons.io.IOUtils

I'm using the answer on How to convert InputStream to virtual File which uses org.apache.commons.io.IOUtils to copy the given InputStream to a FileOutputStream in order to create a File. Should I close the InputStream given?
Ignasi
  • 5,887
  • 7
  • 45
  • 81
8
votes
4 answers

Compress directory into a zipfile with Commons IO

I am a beginner at programming with Java and am currently writing an application which must be able to compress and decompress .zip files. I can use the following code to decompress a zipfile in Java using the built-in Java zip functionality as…
StackUnderflow
  • 431
  • 1
  • 3
  • 15
7
votes
0 answers

Error : javax.net.ssl.SSLException: Connection reset (Specific Website only)

Kind Attn Moderators: Before marking this query as duplicate, please note I have checked these questions... java.net.SocketException: Connection reset What's causing my java.net.SocketException: Connection reset? Getting error…
iCoder
  • 1,406
  • 6
  • 16
  • 35
1
2 3
12 13