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

Java RandomAccessFile truncate from start

I know how to truncate a RandomAccess file so that bytes at the end are removed. raf.getChannel().truncate(file.length() - 4); or raf.setLength(file.length() - 4); But how to truncate a RandomAccessFile in such a way that bytes at the start is…
retromuz
  • 809
  • 9
  • 26
6
votes
4 answers

Scanner on text file hasNext() is infinite

I'm writing a simple program in Java and it requires reading data from a text file. However, I'm having trouble counting lines. The issue seems generic enough for a simple Google search but I may not even be searching the right things. The textbook…
AvaMango
  • 63
  • 1
  • 1
  • 3
6
votes
2 answers

File.listFiles() is returning null in android 11

I was creating an application to test whether File.listFiles() method is working or not. To check this I made an application and I used it there but this returning null in place of an array. This is my full code please help and I have granted all…
Rajkumar
  • 79
  • 1
  • 5
6
votes
2 answers

How to convert List to the csv byte array safely?

Initially I had the following code: Attempt 1 try (var output = new ByteArrayOutputStream(); var printer = new CSVPrinter(new OutputStreamWriter(output), CSVFormat.DEFAULT)) { printer.printRecord(EMAIL); for (MyBean mb : items) { …
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
6
votes
3 answers

BufferedReader doesn't read all lines from file

I am trying to read /proc/net/xt_qtaguid/stats in Android 6. Using cat command, I get this: 2 a0 0 0 123456 311 48329 737 48 1 3 b0 0 0 0 0 0 0 0 4 c0 123456 311 48329 737 48 1 5 d0 111111 111 22222 222 33 1 My java code tries to read the file line…
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
6
votes
4 answers

JAVA : read and write a file together

I am trying to read a java file and modify it simultaneously. This is what I need to do : My file is of the format : aaa bbb aaa ccc ddd ddd I need to read through the file and get the count of the # of occurrences and modify the duplicates to get…
sharath
  • 3,501
  • 9
  • 47
  • 72
6
votes
3 answers

The Properties.load would close the InputStream?

I saw this example, and I didn't see the close() method invoked on the InputStream, so would prop.load() close the stream automatically? Or is there a bug in the example?
Jason
  • 1,115
  • 14
  • 25
6
votes
2 answers

File last access time and last modified time in java?

In my application I read file using following method, public void readFIleData(String path) { BufferedReader br = null; try { String sCurrentLine; br = new BufferedReader(new FileReader(path)); while ((sCurrentLine =…
Hasitha
  • 558
  • 1
  • 12
  • 26
6
votes
1 answer

Writing stax XML to String

I am using stax to create XML document that I need for my web app. Currently I am creating my XML in a file like this: XMLOutputFactory factory = XMLOutputFactory.newInstance(); String output=null; try { …
ForeverStudent
  • 2,487
  • 1
  • 14
  • 33
6
votes
3 answers

Why is File.exists() behaving flakily in multithreaded environment?

I have a batch process running under java JDK 1.7. It is running on a system with RHEL, 2.6.18-308.el5 #1 SMP. This process gets a list of metadata objects from a database. From this metadata it extracts a path to a file. This file may or may not…
Steve Cohen
  • 4,679
  • 9
  • 51
  • 89
6
votes
2 answers

Serialization:java.io.StreamCorruptedException: invalid stream header: 0AACED00

I'm a student practicing my File IO skills and I am coming up against a problem with reading Objects from a file using ObjectInputStream. The code is consistently throwing an InvalidClassException and I can't find how the code is throwing it online…
Plewistopher
  • 73
  • 1
  • 1
  • 7
6
votes
1 answer

How do I read Windows NTFS's Alternate Data Stream using Java's IO?

I'm trying to have my Java application read all the data in a given path. So files, directories, metadata etc. This also includes one weird thing NTFS has called Alternate Data Stream (ADS). Apparently it's like a second layer of data in a directory…
Pt. Terk
  • 462
  • 4
  • 13
6
votes
1 answer

Does File.delete() delete the pointer of the File object?

My co-workers and I are having an argument about how the File.delete() method works in Java. In our code: File outFile = new File("/dir/name.ext"); if(outFile.exists()) outFile.delete(); FileInputStream inStream = new…
Zibbobz
  • 725
  • 1
  • 15
  • 41
6
votes
1 answer

Create a temporary file from a base64 string with rapture-io

So, basically I want to create a temporary file from a base64 string content. Right now, I'm doing this with native java-io functions. But I would like to achieve the same result using the rapture-io library for scala. So my question would be, is…
maya.js
  • 1,147
  • 12
  • 25
6
votes
2 answers

Zip file created on server and download that zip, using java

I have the below code got from mkyong, to zip files on local. But, my requirement is to zip files on server and need to download that. Could any one help. code wrote to zipFiles: public void zipFiles(File contentFile, File navFile) { byte[]…
DDphp
  • 479
  • 2
  • 5
  • 17