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

renaming file while renaming directory

Trying to rename both directory name and file name. try { File dir = new File("DIR"); dir.mkdir(); File file1 = new File(dir,"myfile1.txt"); file1.createNewFile(); File file2 = new…
Pradeep
  • 1,193
  • 6
  • 27
  • 44
4
votes
3 answers

Java I/O - Simulate input for System.console()

I am writing a JUnit for a program created in an exercise. That means the test needs to cover as many cases as possible and I don't have any influence on how certain things in the program are implemented. Also, the program runs an infinite loop…
4
votes
3 answers

The system cannot find the file specified java

Yes, I already know this question is a duplicate, but just bear with me here. None of the other questions answered this. This is my code: package pc.setup; import java.io.IOException; public class DirectoryCreator { public static void…
Lucas Baizer
  • 305
  • 2
  • 5
  • 13
4
votes
2 answers

Modify a hidden file in Java

I have a file that user downloads and then I execute a command within java to hide the file: Runtime.getRuntime().exec("attrib +H myFile.txt"); Now later I need to access that hidden file but I'm getting java.io.FileNotFoundException: myFile.txt…
Marquinio
  • 41
  • 1
  • 3
4
votes
2 answers

How to list only N files in directory using java

If I have a directory contains a lot of files (about 1000 file). Some of these files named .processed and other not. How can I list only 10 unprocessed files. I am using this code to filter the processed file. File[] inputFileList =…
Fanooos
  • 2,718
  • 5
  • 31
  • 55
4
votes
1 answer

java nio Files.copy throwing Java heap space out of memory

I am trying to create a zip file with collection of files. I used java.nio.Files class to do this: Files.copy( toBeAdded,internalTargetPath, StandardCopyOption.REPLACE_EXISTING ); It is running out of heap memory due to file size is…
JAVAC
  • 1,230
  • 3
  • 17
  • 38
4
votes
3 answers

Reading and Writing in Parallel in Java

I have a problem with reading and writing to a file in a 'shared mode'. What my application needs is to be able to access file -or open- in a shared mode so that if one thread is writing to a file another should be able read from it. I have seen…
Guillotine1789
  • 342
  • 4
  • 12
4
votes
3 answers

create pdf from binary data in java

I'm getting this string from a web service. "JVBERi0xLjQKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAyIDAgUgovR3JvdXAgPDwvVHlwZSAvR3JvdXAgL1MgL1RyYW5zcGFyZW5jeSAvQ1MgL0RldmljZVJHQj4" It is supposed to be a pdf file, i tried this…
OJVM
  • 1,403
  • 1
  • 25
  • 37
4
votes
2 answers

System.out in DataOutputStream is not printing on the console

I am trying the following code using the DataOutputStream. The OutputStream passed to the DataOutputStream is not printing anything. Please see my below code and pllease tell me anything wrong in this code. public class DataStreamsExample { public…
Sivaranjani D
  • 512
  • 4
  • 16
4
votes
4 answers

preCalculate file stream checksum

i'm trying to ensure an output File integrity in case of disk out of space , network problem ,or any anyException that might occur during the streaming to file process . is there a way to precalculate the FileStream checkSum before writing to disk…
Genjuro
  • 7,405
  • 7
  • 41
  • 61
4
votes
3 answers

Understanding Binary, ByteStream and Characters in java

I'm having some difficulty digesting the some concepts in the Java IO classes. For instance there are two types of streams, byte and char. Byte streams as I understand read byte by byte. 1. If a char in java is stored as a 16bit (two byte) data…
jmreader
  • 522
  • 5
  • 10
4
votes
3 answers

reading a file from HDFS only after it is fully written and closed

I have two processes running. One is writing files to an HDFS and the other is loading those files. The first process (The one that writes the file) is using: private void writeFileToHdfs(byte[] sourceStream, Path outFilePath) { FSDataOutputStream…
forhas
  • 11,551
  • 21
  • 77
  • 111
4
votes
4 answers

How can I improve the speed of reading big-size file in Java?

I just read a file whose size is 167MB and line number is 1884000. The method I use is BufferedReader to get the effect of reading it in line. What I noticed is that the process of reading the file is growing slower and slower as the current line…
Judking
  • 6,111
  • 11
  • 55
  • 84
4
votes
2 answers

Universal Image Loader for external storage files

Hello I use Universal Image Loader to load images from the device , now it works, but if the file path contains a "space character" the image does not get displayed and log records show that there is a FileNotFoundException . I tried to open the…
user4o01
  • 2,688
  • 4
  • 39
  • 54
4
votes
1 answer

StreamCorruptedException with ObjectInputStream and ByteArrayInputStream

I have a number of objects written to disk using ObjectOutputStream. During reading, I firstly retrieve the file as a ByteArray for some implementation reasons, I want to read the buffered array and decode the data from it. Here is a code…
DotNet
  • 697
  • 2
  • 7
  • 23