Can anyone explain precisely what IOWait is?

I know it’s the time spent by the CPU waiting for a IO operations to complete, but what kind of IO operations precisely? What I am also not sure, is why it so important? Can’t the CPU just do something else while the IO operation completes, and then get back to processing data? Yes, the … Read more

Beginner Python: Reading and writing to the same file

Updated Response: This seems like a bug specific to Windows – http://bugs.python.org/issue1521491. Quoting from the workaround explained at http://mail.python.org/pipermail/python-bugs-list/2005-August/029886.html the effect of mixing reads with writes on a file open for update is entirely undefined unless a file-positioning operation occurs between them (for example, a seek()). I can’t guess what you expect to happen, but seems most … Read more

Create a new line in Java’s FileWriter

If you want to get new line characters used in current OS like \r\n for Windows, you can get them by System.getProperty(“line.separator”); since Java7 System.lineSeparator() or as mentioned by Stewart generate them via String.format(“%n”); You can also use PrintStream and its println method which will add OS dependent line separator at the end of your string automatically (BTW System.out is also instance of PrintStream).

Categories io

Java Scanner doesn’t wait for user input

It’s possible that you are calling a method like nextInt() before. Thus a program like this: demonstatres the behavior you’re seeing. The problem is that nextInt() does not consume the ‘\n’, so the next call to nextLine() consumes it and then it’s waiting to read the input for y. You need to consume the ‘\n’ before calling nextLine(). (actually a better way would be to call … Read more

Categories io