ioexception

Does close ever throw an IOException?

心已入冬 提交于 2019-11-27 01:41:50
After providing some answers here, and reading some comments, it would seem that, in practice IOException is never thrown on close for file I/O. Are there any cases in which calling close on a Stream/Reader/Writer actually throws an IOException? If an exception is actually thrown, how should it be dealt with? For files, you may not see IOException thrown often on close(), but you'll definitely see it for non-File I/O like closing sockets to the network. Here's an example of a Java bug where closing a UDP socket eventually caused an IOException to be thrown. TofuBeer I have found two cases:

Java - What throws an IOException

瘦欲@ 提交于 2019-11-27 00:56:43
java.io.IOException seems to be the most common type of exception, coincidentally, it seems to also be the most ambiguous. I keep seeing the throws IOException whenever writing with sockets, files, &c. I've never actually had one fired on me, however, so I'm wondering what it is that is supposed to fire the exception. The documentation isn't very helpful in explaining what's going on: Signals that an I/O exception of some sort has occurred. This class is the general class of exceptions produced by failed or interrupted I/O operations. Can someone please explain some instances where an

Cannot make file java.io.IOException: No such file or directory

回眸只為那壹抹淺笑 提交于 2019-11-26 23:19:08
问题 I am trying to create a file on the filesystem, but I keep getting this exception: java.io.IOException: No such file or directory I have an existing directory, and I am trying to write a file to that directory. // I have also tried this below, but get same error // new File(System.getProperty("user.home") + "/.foo/bar/" + fileName); File f = new File(System.getProperty("user.home") + "/.foo/bar/", fileName); if (f.exists() && !f.canWrite()) throw new IOException("Kan ikke skrive til

Android playing resource files from internal storage causes MediaPlayer.prepare to give IOException

本秂侑毒 提交于 2019-11-26 23:09:17
问题 My app plays audio resource files from the internal directory designated for my app (/data/data/com...). It seems to download the files to that location okay, setDataSource(String path) doesn't throw any exceptions, but MediaPlayer.prepare() throws IOException.The same code works on the SD card. Why is this happening? EDIT: Let's assume this is the code; it's simpler than my code and it throws the same exception: package com.app.MediaPlayerTest; public class MediaTest extends Activity {

How to check if IOException is Not-Enough-Disk-Space-Exception type?

独自空忆成欢 提交于 2019-11-26 22:07:35
How can I check if IOException is a "Not enough disk space" exception type? At the moment I check to see if the message matches something like "Not enough disk space", but I know that this won't work if the OS language is not English. Justin You need to check the HResult and test against ERROR_DISK_FULL (0x70) and ERROR_HANDLE_DISK_FULL (0x27) , which can be converted to HResults by OR 'ing with 0x80070000 . For .Net Framework 4.5 and above, you can use the Exception.HResult property: static bool IsDiskFull(Exception ex) { const int HR_ERROR_HANDLE_DISK_FULL = unchecked((int)0x80070027); const

How should I read from a buffered reader?

只愿长相守 提交于 2019-11-26 21:26:04
问题 I have the following example of reading from a buffered reader: while ((inputLine = input.readLine()) != null) { System.out.println("I got a message from a client: " + inputLine); } The code in the loop println will be executed whenever something appears in the buffered reader ( input in this case). In my case, if a client-application writes something to the socket, the code in the loop (in the server-application) will be executed. But I do not understand how it works. inputLine = input

Cannot delete file used by some other process

无人久伴 提交于 2019-11-26 21:07:11
I am displaying some image in my wpf app using following code: <Image Source="{Binding Path=TemplateImagePath, Mode=TwoWay}" Grid.Row="3" Grid.Column="2" Width="400" Height="200"/> and setting it's binding property inside code behind's constructor by navigating through some directory, below is the code: DirectoryInfo Dir = new DirectoryInfo(@"D:/Template"); if (Dir.Exists) { if (Dir.GetFiles().Count() > 0) { foreach (FileInfo item in Dir.GetFiles()) { TemplateImagePath = item.FullName; } } } but if user upload some other image then I need to delete this old image which is I am doing in the

MediaPlayer.setDataSource causes IOException for valid file

你。 提交于 2019-11-26 20:52:43
This code used to work. Then, maybe I changed something, somewhere (or if I know Android right, an update introduced a bug in the media player). It stopped working on some devices! Especially my Nexus S (2.3.6). The file test.m4a (17 775 201 bytes) was downloaded by the app. To verify its integrity, I copied it to the SD and played it on my PC. No problem! Also binary-compared it with the original file, and it matched 100%. try { _mediaPlayer = new MediaPlayer(); _mediaPlayer.setOnCompletionListener(this); _mediaPlayer.setOnPreparedListener(this); _mediaPlayer.setOnSeekCompleteListener(this);

java.io.IOException : No authentication challenges found

大兔子大兔子 提交于 2019-11-26 20:26:32
I am newbie to android and this is my first project on android. I am struggling with "authentication" problem for more than a day. I tried several options but none of them worked. Basically, I want to call a REST API and get response. I am sure that there is no problem in API as I use the same one in another iOS application. I pass authorization header but still authentication no found message is shown. I found few question on stackoverflow related to this, but some of them did not work and some does not make sense to me. I get status code 401 . I know this means either no authentication

How can I fix an “IOException: Stream closed” exception using System.in?

梦想的初衷 提交于 2019-11-26 18:35:40
问题 I'm writing a simple program that reads and processes file content using a BufferedReader . BufferedReader br = new BufferedReader( new InputStreamReader(System.in) ); System.out.println("Enter the file name to read"); String fileName = br.readLine(); br.close(); // Process file contents br = new BufferedReader( new InputStreamReader(System.in) ); System.out.println("Enter another file name to read"); fileName = br.readLine(); br.close(); But when I call second br.readLine() to read another