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

java.nio.file.FileAlreadyExistsException how to resolve this in java7

i am writing a code i am creating a directory with java nio api my segment of code is Path target = Paths.get(""+folder_path+xx[0]); Set perms = null; if(xx[2].toLowerCase().equals("read")) perms…
mathlearner
  • 7,509
  • 31
  • 126
  • 189
4
votes
2 answers

Android bluetooth socket.connect fails; Throws java IO exception

I'm using a code derived from Bluetooth tutorial on Android Developer page. My app tries to connect to a BT weighing scale and record the weight information. My program throws an error when it attempts to perform a BluetoothSocket.connect(); The…
Student91
  • 41
  • 1
  • 2
4
votes
2 answers

Delete a file and its parents directories if they're empty. ( Java )

I'm trying to do a simple method that deletes a file its upper directories if they are empty till it reaches a base directory, but I cannot make it work. It deletes the file, its parent directory, but, its next parent isn't deleted as it throws a…
giorgiline
  • 1,271
  • 4
  • 21
  • 35
4
votes
1 answer

Exception from resource close in finally hides another -- who cares?

Firstly, sorry for asking a question on what must be a well-worn topic. I've come across loads of questions with answers suggesting to swallow (catch and ignore/log) potential exception from methods that close resources in finally blocks. It seems…
AmyGamy
  • 101
  • 7
4
votes
1 answer

Android saving file to cache directory

I am trying to do something simple like save a file to a cache directory in Android and I am having a lot of problems. I am using Simple serializer to write out my file into xml. Here is my code: public void testWrite(ListDefinitions ld) { …
AlexIIP
  • 2,461
  • 5
  • 29
  • 44
4
votes
4 answers

Java IO inputstream blocks while reading standard output & standard error of an external C program

I've posted the same question here a few days ago(Java reading standard output from an external program using inputstream), and I found some excellent advices in dealing with a block in while reading ( while(is.read()) != -1)), but I still cannot…
Lawrence Park
4
votes
0 answers

java.io.IOException: Cannot run program "pwd.sh": error=13, Permission denied ... How do I get environment variables in Eclipse debug session?

I have a weird problem while trying to execute a system process from within a Java program. Getting permission denied error: java.io.IOException: Cannot run program "pwd.sh": error=13, Permission denied Very similar to this: Permission denied error…
John L
  • 397
  • 3
  • 12
3
votes
2 answers

What is the proper way to open a stream in Java

I will be performing a lecture on Java for students of Physics, and I would like to know how to properly open a file. In many my proffesional apps I did somethings like that: BufferedWriter bufferedWriter = new BufferedWriter(new…
jb.
  • 23,300
  • 18
  • 98
  • 136
3
votes
2 answers

Strange output when running a loop

Can anyone tell me why I always have this strange output after running this loop? Is this a threading issue or what? for(int i=0;i<10;i++){ System.out.println("out: "+i); System.err.println("err: "+(i+1)); } ->OUTPUT: err: 1 …
imanis_tn
  • 1,150
  • 1
  • 12
  • 33
3
votes
4 answers

File.canWrite is not working as per expectations

i am trying to check whether a file is writable or not. i have changed the file permission by myself for all users. but if i try to run the program, it show "true" as a response. if i allow the permissions, then also it is showing "true". Whats is…
kunal dexit
  • 97
  • 2
  • 9
3
votes
2 answers

Write data to a file from a BufferedReader?

In Java... I have data stored in a BufferedReader. (I got it as a response to an HTTP post request.) How do I write this (binary) data to a file? I know how to write Strings to files, but how do I take the data in the BufferedReader and put it into…
rustybeanstalk
  • 2,722
  • 9
  • 37
  • 57
3
votes
1 answer

Trouble saving file in SD card with special characters in filename

My application has a function to save file on SD card. Following is my code to save the file try { File mediaDir = new File( Environment.getExternalStorageDirectory(), "Media"); if (!mediaDir.exists()) { …
PH7
  • 3,926
  • 3
  • 24
  • 29
3
votes
5 answers

Java stream misconceptions... some clarification?

I understand that byte streams deal with bytes and character streams deal with characters... if I use a byte stream to read in characters, could this limit me to the sorts of characters I might read? For instance, bytes are read in as 8 bit bytes,…
wulfgarpro
  • 6,666
  • 12
  • 69
  • 110
3
votes
0 answers

How to create custom serialization in Kotlin with java.io.serializable

I am attempting to serialize with java.io.Serializable a Kotlin class that is already serializable with kotlinx.serialization. The java serialization will not work out of the box because some fields in the class are not serializable by default. But,…
Eytan
  • 728
  • 1
  • 7
  • 19
3
votes
2 answers

Can Java Files.walk continue executing after encountering an exception error

This is my first time working with Files.walk in Java, and I rather like it, especially the Path class. It's robust and versatile. What I'm not liking, however, is that when walking a folder, if the iterator runs into a snag ... like it hits a…
Michael Sims
  • 2,360
  • 1
  • 16
  • 29