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

ColdFusion 11 not closing java.io.FileInputStream

I have a script in ColdFusion that is reading some files .EML from a local SMTP server and extracting some data from the files. I have everything working fine, but from time to time the files gets locked and I cannot delete the file and I get the…
Ennio
  • 1,147
  • 2
  • 17
  • 34
3
votes
1 answer

When Use FileChannel to read()/write() files?

I am reading the book Thinking in Java, which explains the java.nio.* package and says that NIO is faster than reading and writing files with traditional IO streams. Why? I have reviewed the following information: IO stream is byte oriented,…
Citron
  • 53
  • 3
3
votes
1 answer

How to create a FileSystem object for a *directory* using an absolute path?

I'm creating a command line application that needs to output some files (more than one) into either a ZIP file or a plain folder depending on the paramters given. My approach is to encapsulate the target (plain folder/ZIP file) with a FileSystem. My…
Timothy Truckle
  • 15,071
  • 2
  • 27
  • 51
3
votes
1 answer

Why any file can be read with using java.security.SecurityManager in java?

I just want some files to be read and written in my Java program. So I use java.security.SecurityManager to manage this, but it seems unsatisfactory. The Main.java file is below import java.io.*; import java.util.*; public class Main { static…
islands
  • 43
  • 4
3
votes
3 answers

read whole file in a folder

Is there a way in Java where I can specify a directory in java and it reads the whole file one by one? Otherwise is there a way to do a regex file read in java? So if all the files in the folder all starts with gh001_12312 gh002_12312, gh003_12911,…
aherlambang
  • 14,290
  • 50
  • 150
  • 253
3
votes
1 answer

myFile.isFile() or myFile.isDirectory() is there any third type of function possible?

I was writing a common function to check if the variable contains a file or a directory. So I came up with an idea to check it using a boolean return-type function. something like this : function boolean checkFileOrDirectory(File myFile){ //…
Mohd Naved
  • 448
  • 6
  • 20
3
votes
2 answers

why java.io.PrintStream is not needed in System.out.println()?

So I ask myself why I don't have to import java.io.PrintStream to use System.out. I know that java.lang is imported by default by the compiler. Allright. Because System is a class of java.lang I can use the field System.out. But this field has the…
Tri So
  • 33
  • 3
3
votes
1 answer

FileBackedOutputStream use case (Guava)

I came across FileBackedOutputStream class from Google Guava library and was wondering if it's suitable to be used as a kind of a buffer: once every day, a process in my webapp generates tens of thousands of lines (each containing about…
John Manak
  • 13,328
  • 29
  • 78
  • 119
3
votes
1 answer

Decorator pattern java.io.reader

For a school report I have to explain how the java.io.Reader package implements the Decorator pattern. I have seen multiple explanations for the java.io package (here for example) but not for the java.io.Reader package (if that's even any…
Mees Kluivers
  • 520
  • 2
  • 6
  • 26
3
votes
2 answers

new line for every new stream in SequenceInputStream

I have two files, test-1.text (content is Data from test-1) and test-2.text (content is Data from test-2). when I use SequenceInputStream to read from two streams, output comes either in one straight line like Data from test-1Data from test-2 or…
user252514
  • 307
  • 1
  • 3
  • 14
3
votes
1 answer

Axis2 File Upload by chunk

I'm trying to upload file using Axis2 web service by 1024 chunk size. My server side looks like this: public void appendChunk(int count, byte[] buffer){ FileOutputStream fos = null; try { File destinationFile = new…
danny.lesnik
  • 18,479
  • 29
  • 135
  • 200
3
votes
1 answer

Reading file containing random numbers, sorting it and than writing to other file

In an interview I was asked the following question, There is a file named sourceFile.txt containing random numbers aligned one below other like below, 608492 213420 23305 255572 64167 144737 81122 374768 535077 866831 496153 497059 931322 same…
Rahul Shivsharan
  • 2,481
  • 7
  • 40
  • 59
3
votes
3 answers

Is it possible to get the errno behind an IOException?

I’m working with sockets in Java, and when the socket is closed by the other side, I might get exceptions like: java.io.IOException: Broken pipe java.io.IOException: Connection reset by peer In that case, I know the connection is broken (that’s…
Lucas Werkmeister
  • 2,584
  • 1
  • 17
  • 31
3
votes
1 answer

Reading File using Java given a starting and an ending line number

I am new with Java programming and i wasn't able to find an answer to my problem anywhere. How to read few lines of a file and store it in a String (or a list of Strings). For example from a file of 1000 lines i need to read only 200 lines starting…
3
votes
2 answers

Java open files with given extension in a directory hierarchy

I implemented a recursive method to traverse a directory hierarchy looking for files with a given extension; however I'm not convinced this is the easiest way and it involves isDirectory(), listFiles(), etc. Is there a way to do that without…
Cedric H.
  • 7,980
  • 10
  • 55
  • 82