io

How to check For File Lock in C# ?

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. ...

How do you open a file in C++?

I want to open a file for reading, the C++ way. I need to be able to do it for text files, which would involve some sort of read line function, and a way to do it for binary files, which would provide a way to read raw data into a char* buffer. ...

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? } ...

Why doesn't Ruby have a real StringBuffer or StringIO?

I recently read a nice post on using StringIO in Ruby. What the author doesn't mention, though, is that StringIO is just an "I." There's no "O." You can't do this, for example: s = StringIO.new s << 'foo' s << 'bar' s.to_s # => should be "foo\nbar" # => really is ''` Ruby really needs a StringBuffer just like the one Java has. Stri...

Send messages to program through command line

I have this program, we'll call it Host. Host does all kinds of good stuff, but it needs to be able to accept input through the command line while it's running. This means it has to somehow send its other process data and then quit. For example, I need to be able to do this: ./Host --blahblah 3 6 3 5 This should somehow end up calling...

Creating tempory folders

I am working on a program that needs to create a multiple temporary folders for the application. These will not be seen by the user. The app is written in VB.net. I can think of a few ways to do it such as incremental folder name or random numbered folder names, but I was wondering, how other people solve this problem? ...

How do you place a file in recycle bin instead of delete?

Programmatic solution of course... Man i wish i could choose both the VB and Unmanaged as an answer ;) Thanks for both. ...

I/O permission settings using .net installer

I am creating a program that will be installed using the .net installer project. The program writes to settings files to its directory in the Program Files dir. It believe there are some active directory settings that will prevent the application from righting to that directory if a limited user is running the program. Is there away to c...

Implementing a log watcher

I wondering how in C/C++ you can implement a program (similar to tail -f) that watches for new lines added to a log file and then process them? ...

"All Users" Folder

Is there a .net variable that returns the "All Users" directory? ...

Hooking my program with windows explorer's rename event

Is there any way, in any language, to hook my program when a user renames a file? For example: A user renames a file and presses enter (or clicks away) to confirm the rename action. BEFORE the file is actually renamed, my program "listens" to this event and pops up a message saying "Are you sure you want to rename C:\test\file.txt to C:...

Binary buffer in Python

In Python you can use StringIO for a file-like buffer for character data. Memory-mapped file basically does similar thing for binary data, but it requires a file that is used as the basis. Does Python have a file object that is intended for binary data and is memory only, equivalent to Java's ByteArrayOutputStream? The use-case I have i...

Is there a reason to use BufferedReader over InputStreamReader when reading all characters?

I currently use the following function to do a simple HTTP GET. public static String download(String url) throws java.io.IOException { java.io.InputStream s = null; java.io.InputStreamReader r = null; //java.io.BufferedReader b = null; StringBuilder content = new StringBuilder(); try { s = (java.io.InputStrea...

How to find out if a file exists in C# / .NET?

I would like to test a string containing a path to a file for existence of that file (something like the -e test in Perl or the os.path.exists() in Python) in C#. ...

Easy way to write contents of a Java InputStream to an OuptutStream

I was surprised to find today that I couldn't track down any simple way to write the contents of an input stream to an output stream in Java. Obviously, the byte buffer code isn't difficult to write, but I suspect I'm just missing something which would make my life easier (and the code clearer). So, given an InputStream in and an Output...

fprintf return success but can't write to an existin file

In my codes, fprintf return successful by returning the number of bytes written in STREAM, but in the actual file the string I put is not there. ...

When can DataInputStream.skipBytes(n) not skip n bytes?

The Sun Documentation for DataInput.skipBytes states that it "makes an attempt to skip over n bytes of data from the input stream, discarding the skipped bytes. However, it may skip over some smaller number of bytes, possibly zero. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped i...

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? ...

Starting a process with inherited stdin/stdout/stderr in Java 6

If I start a process via Java's ProcessBuilder class, I have full access to that process's standard in, standard out, and standard error streams as Java InputStreams and OutputStreams. However, I can't find a way to seamlessly connect those streams to System.in, System.out, and System.err. It's possible to use redirectErrorStream() to g...

How do I create an in-memory Handle in haskell?

I want something that looks like a file Handle but is really backed by an in-memory buffer to use for IO redirects. How can I do this? ...