file-io

Outputting from file one line at a time

I'm trying to output text from a file one line at a time. I'm currently hardcoding it and I have this so far: int main(int argc, char *argv[]) { int x; int k; int limit = 5; FILE *file; file = fopen("C:\\Documents and Settings\\jon\\My Documents\\Visual Studio 2008\\Projects\\Project1\\Assignment8_2\\Debug\\TestFil...

Method in Java to create a file at a location, creating directories if necessary?

I am attempting to write a file using java.io, where I am trying to create it at the location "some/path/to/somewhere/then-my-file". When the file is being created, any of the directories on the path may or may not exist. Rather than throw an IOException because there are no such directories, I would like the directories to be created tr...

File I/O in C++

I have a data file where I need to read a datum from each line and store it. And then depending on the value of one of those datums store that data in an array so that I can then calculate the median value of all of these data. The line of data is demographic information and depending on the geographic location, address of a person. I n...

Handling large files

Hello there, I need to do some file I/O(mainly reading) on a very large file(>3GB), can someone suggest the best way to do so? I want to do in C++. ~calvin ...

Creating a temp file is incredibly slow.

Any reason why a call to File.createTempFile("prefix", ".suffix", new File("C:\\"); might take 40-50 seconds to complete? Update: I knocked up a little test harness that benchmarks creating 100 test files on C:\ and the default tmp folder. Specifying "C:\" is consistently ~0.9ms slower than just leaving it on the default, allowing fo...

Random access of multiple files and file caching

This relates to some software I've been given to "fix". The easiest and quickest solution would make it open and read 10 random files out of hundreds and extract some very short strings for processing and immediately close them. Another process may come along right after that and do the same thing to different, or the same, random files ...

Most efficient way to create and write multiple 10 KB text files?

We're using the following approach to writing out text files: public void WriteFile(string filePath, string contents) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException("filePath"); } if (contents == null) { throw new ArgumentNullException("contents"); } if (File.Exists(filePath)) { throw ne...

Remove Duplicates From File (vs COBOL)

This Cobol question really piqued my interest because of how much effort seemed to be involved in what seems like it would be a simple task. Some sloppy Python to remove file duplicates could be simply: print set(open('testfile.txt').read().split('\n')) How does removing duplicates in the same file structure as above in your langua...

Is it possible to write to a CD with .NET?

Possible Duplicate : Write to CD from .net I have a data file in f:\ drive named 'cd.txt'. I want to write this file to a CD i.e E:\. String source ="F:\\cd.txt"; String destination="E:\\cd.txt"; File.copy(sorce,destination); The above line is throwing exception saying "Access to the path 'E:\cd.txt' is denied". What is the soluti...

Why doesn't Scala Source close the underlying InputStream?

I'm using Scala Source.fromFile however I can't seem to find a nice way of getting it to close the underlying InputStream once the file has been read. Here's my code that will fail with an AssertionError because the file cannot be deleted. def main(args : Array[String]) : Unit = { val myFile = new File("c:/tmp/doodah.txt") v...

C# File I/O Efficiency

Hi, I have done a homework assignment, here is the problem statement: Your program should work as follows: Ask the user to give you a file name. Get the file name and save it. Open the file. From the file read a temperature and a wind speed. Both values should be stored in variables declared as double. The file is a text file. Each l...

What are the trade-offs between procedurally copying a file versus using ShellExecute and cp?

There are at least two methods for copying a file in C/C++: procedurally and using ShellExecute. I can post an explanation of each if needed but I'm going to assume that these methods are known. Is there an advantage to using one method over the other? ...

C#: Writing a CookieContainer to Disk and Loading Back In For Use

I have a CookieContainer extracted from a HttpWebRequest/HttpWebResponse session named CookieJar. I want my application to store cookies between runs, so cookies collected in the CookieContainer on one run of the program will be used the next run, too. I think the way to do this would be to somehow write the contents of a CookieContaine...

How to read unsigned short from file?

I have a bitmap image that I am parsing and I need to be able to open the file and store the first unsigned short. I tried to accomplish this using FILE and fscanf() but fscanf() always fails and returns 0 (number of items successfully read). FILE *pFile = fopen ( fileName->c_str() , "r" ); if ( pFile == NULL ) { cerr << "couldn't...

Using LockFileEX in C#

Background I'm trying to implement block file locking in my C# application. The built-in FileStream.Lock method throws an exception if it is unable to acquire the lock. The underlying LockFile method returns a status code however I'd prefer not to use a spin-lock to wait for the file to be unlocked. Question Does anyone have any c...

Implementing a fixed-size log file, or a circular buffer on disk

I checked this question, but it's not what I'm looking for. I'm trying to figure out how to cap a log file's size (say, 10MB), and as soon as it's hit, either: start writing to the beginning, rather than appending, or keep appending, but delete the contents from the beginning as I do so Don't really care about language - as long as...

Modifying an IO stream in-place? Ruby.

I've been writing a ruby programme that merges the content of two files. For example if a torrent have been downloaded two times separately, it tries to merge their contents for the blocks which have been completed. So, I've been looking for a method which modifies a stream only at the place required and saves only that block instead of...

Are there better ways to overwrite a file then check for changes (in C#)?

Situation: I have a C# program which does the following: Generate many files (replacing the ones generated last time the program ran.) Read those files and perform a time-consuming computation. Problem: I only want to perform the time-consuming computation on files which have actually changed since the last time I ran the program. ...

Migrating from processing many small data files to a few large files in ruby

What should I keep in mind when migrating from processing many small data files to a few large data files in ruby? Background: I'm a bioinformatician who is processing next generation sequencing data, which produces about one million sequences per run. I previously saved each one of the million sequences to its own file, and did a few p...

File upload in ASP.NET - How can I prevent exceptions?

I have a FileUploader control in my web form. If the file being uploaded is already present, I want to delete it, and overwrite it with the newly-uploaded file. But I get an error, as the file is in use by another process, and thus the application can't delete it. Sample code: if (FUpload.HasFile) { string FileName = Path.GetFileNam...