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
2 answers

Is this a typo in the java tutorials?

I was going through the Java TCP Client Server tutorials where they are explaining how a echo server works and how a TCP client interacts with the echo server. For the TCP Client, they have given this snippet and are explain what it is: String…
Krimson
  • 7,386
  • 11
  • 60
  • 97
3
votes
2 answers

How do you write to a log file in Clojure, using core.async?

I want to use core.async as a logger that writes out to a file, so I created a test.txt file, stuck it in my resources folder and wrote this code: (use 'clojure.java.io) (use 'clojure.core.async) (def print-chan (chan)) (go (loop [] …
kurofune
  • 1,055
  • 12
  • 26
3
votes
1 answer

How can I read text from a file in Java with streams of size I choose?

So I can read a text file with Java like this just fine: File file = new File("C:/text.txt"); Scanner scanner = new Scanner(file,"utf-8"); while (scanner.hasNext()) { scanner.nextLine(); // rest of the code... I am not 100% sure but I…
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
3
votes
1 answer

Can't a Reader read *directly* from a StringBuilder?

I'm using an API that requires a Reader to read from, and this Reader should actually read from a (potentially very large) StringBuilder. But using this: new StringReader(stringBuilder.toString()); ...will copy the internal StringBuilder's char…
xav
  • 5,452
  • 7
  • 48
  • 57
3
votes
2 answers

Asking user for multiple input

I am trying to write a program which will keep asking a user for an integer until they input a value which isn't an integer, at which point the program stops. Here is what I have so far: import java.util.Scanner; import java.util.ArrayList; public…
user2975192
  • 317
  • 2
  • 6
  • 18
3
votes
2 answers

Does new File("...") lock the file?

I read that new File("path") doesn't physically create a file on disk. Though in the API it is said: Instances of this class may or may not denote an actual file-system object such as a file or a directory. If it does denote such an object then…
Scadge
  • 9,380
  • 3
  • 30
  • 39
3
votes
3 answers

Writing an entire list to a file in java

I am working on a big project where I have more than 1 million lines of data. Data is divided into various files containing 20,000 lines each. Now the data from each file is read line by line and some variable x is concatenated to each line. I am…
Ahmar Ali
  • 1,038
  • 7
  • 27
  • 52
3
votes
3 answers

What is the result of buffering a buffered stream in java?

Was writing the javadoc for : /** * ...Buffers the input stream so do not pass in a BufferedInputStream ... */ public static void meth(InputStream is) throws IOException { BufferedInputStream bis = new BufferedInputStream(is, …
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
3
votes
4 answers

Loading different set of properties in java to an ArrayList

I have a list of properties like this, server1.serverName ="" server1.serverType ="' server1.hostName ="" server1.userName ="" server1.password ="" in a property file and I have 'n' no of sets,like server2, server3,...servern in a property file.…
sbala_20
  • 95
  • 2
  • 4
  • 10
3
votes
0 answers

Asynchronous File copy in java

I want to know how we can move a file to a different location asynchronously, basically one of my program is keep on appending data to a temporary file and another is checking its size on exceeding the predefined size of the temporary file it should…
3
votes
2 answers

JAVA IO : getAbsolutePath()

when i create a new dynamic web project and execute the code below : File file = new File(""); String path = file.getAbsolutePath(); System.out.println(path); I get this result: C:\Users\Toshiba\workspace\Projet . which is good!!!. But when i…
simoi chigo
  • 459
  • 2
  • 7
  • 23
3
votes
1 answer

Using the FileWriter with a full path

I specified the full path of the file location when I created a FileWriter, but I did not see the file being created. I also did not get any error during file creation. Here's a snippet of my code: public void writeToFile(String fullpath, String…
chris yo
  • 1,187
  • 4
  • 13
  • 30
3
votes
1 answer

java: finding char offset, para offset of a word in a text file from the starting of the file?

what i require is the offset(s) for character and para tags in a text file with respect to the START of the FILE. suppose the word is "his", i need to get all the char offset (start,end) of the word occurring as many times inside the

......

Roshan
  • 645
  • 1
  • 11
  • 36
3
votes
1 answer

Reading a log file in java which in currently being written

I have a program running which writes log to a file and I want to read it line by line. I tried using InputStream, particularly DataInputStream, using its available method. But then it doesn't have readLine method, it is deprecated and it was…
r0b0
  • 49
  • 2
  • 6
3
votes
2 answers

Write Parcelable object got java.io.NotSerializableException

I have a class named Shop, which has 2 fields and 1 static field. The class implements Parcelable interface: public class Shop implements Parcelable{ private static int SHOP_ID = 12; private String name; private long fund; …
Mellon
  • 37,586
  • 78
  • 186
  • 264