EzDevInfo.com

io interview questions

Top io frequently asked interview questions

Calculate the execution time of a method [duplicate]

Possible Duplicate:
How to measure how long is a function running?

I have an I/O time taking method which copies data from a location to another. What's the best and most real way of calculating the execution time? Thread? Timer? Stopwatch? Any other solution? I want the most exact one, and briefest as much as possible.


Source: (StackOverflow)

Parsing CSV files in C#

Is there a default/official/recommended way to parse CSV files in C#? I don't want to roll my own parser.

Also, I've seen instances of people using ODBC/OLE DB to read CSV via the Text driver, and a lot of people discourage this due to its "drawbacks." What are these drawbacks?

Ideally, I'm looking for a way through which I can read the CSV by column name, using the first record as the header / field names. Some of the answers given are correct but work to basically deserialize the file into classes.


Source: (StackOverflow)

Advertisements

How to append text to an existing file in Java

I need to append text repeatedly to an existing file in Java. How do I do that?


Source: (StackOverflow)

Non-blocking read on a subprocess.PIPE in python

I'm using the subprocess module to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-blocking or to check if there is data on the stream before I invoke .readline? I'd like this to be portable or at least work under Windows and Linux.

here is how I do it for now (It's blocking on the .readline if no data is avaible):

p = subprocess.Popen('myprogram.exe', stdout = subprocess.PIPE)
output_str = p.stdout.readline()

Source: (StackOverflow)

an htop-like tool to display disk activity in linux [closed]

I am looking for a Linux command-line tool that would report the disk IO activity. Something similar to htop would be really cool. Has someone heard of something like that?


Source: (StackOverflow)

Save and load MemoryStream to/from a file

I am serializing an structure into a MemoryStream and I want to save and load the serialized structure.

So, How to Save a MemoryStream into a file and also load it back from file?


Source: (StackOverflow)

How to check for file lock?

Is there any way to check whether a file is locked without using a try/catch block?

Right now, the only way I know of is to just open the file and catch any System.IO.IOException.


Source: (StackOverflow)

How to redirect output to a file and stdout

In bash, calling foo would display any output from that command on the stdout.

Calling foo > output would redirect any output from that command to the file specified (in this case 'output').

Is there a way to redirect output to a file and have it display on stdout?


Source: (StackOverflow)

Guava equivalent for IOUtils.toString(InputStream)

Apache Commons IO has a nice convenience method IOUtils.toString() to read an InputStream to a String.

Since I am trying to move away from Apache Commons and to Guava: is there an equivalent in Guava? I looked at all classes in the com.google.common.io package and I couldn't find anything nearly as simple.

Edit: I understand and appreciate the issues with charsets. It just so happens that I know that all my sources are in ASCII (yes, ASCII, not ANSI etc.), so in this case, encoding is not an issue for me.


Source: (StackOverflow)

How do you determine the size of a file in C?

How can I figure out the size of a file, in bytes?

#include <stdio.h>

unsigned int fsize(char* file){
  //what goes here?
}

Source: (StackOverflow)

Create file in Ruby

I'm pretty new to Ruby and something has me entirely confused. I'm trying to create a new file and things don't seem to be working as I expect them too. Here's what I've tried:

File.new "out.txt"
File.open "out.txt"
File.new "out.txt","w"
File.open "out.txt","w"

According to everything I've read online all of those should work but every single one of them gives me this:

ERRNO::ENOENT: No such file or directory - out.txt

This happens from irb as well as a ruby file. What am I missing?

Thanks, Civatrix


Source: (StackOverflow)

How to add a Timeout to Console.ReadLine()?

I have a console app in which I want to give the user x seconds to respond to the prompt. If no input is made after a certain period of time, program logic should continue. We assume a timeout means empty response.

What is the most straightforward way of approaching this?


Source: (StackOverflow)

How can I use "puts" to the console without a line break in ruby on rails?

I have a method which goes through a loop -- I want it to output a "." each loop so I can see it in the console. however, it pus a linebreak at the end of each when I use puts ".".

If there a way so that it just has a continuous line?


Source: (StackOverflow)

Avoiding recursion when reading/writing a port synchronously?

All port operations in Rebol 3 are asynchronous. The only way I can find to do synchronous communication is calling wait.

But the problem with calling wait in this case is that it will check events for all open ports (even if they are not in the port block passed to wait). Then they call their responding event handlers, but a read/write could be done in one of those event handlers. That could result in recursive calls to "wait".

How do I get around this?


Source: (StackOverflow)

Do I need to close() both FileReader and BufferedReader?

I'm reading a local file using a BufferedReader wrapped around a FileReader:

BufferedReader reader = new BufferedReader(new FileReader(fileName));
// read the file
// (error handling snipped)
reader.close();

Do I need to close() the FileReader as well, or will the wrapper handle that? I've seen code where people do something like this:

FileReader fReader = new FileReader(fileName);
BufferedReader bReader = new BufferedReader(fReader);
// read the file
// (error handling snipped)
bReader.close();
fReader.close();

This method is called from a servlet, and I'd like to make sure I don't leave any handles open.


Source: (StackOverflow)