file-io

Pattern for saving and writing to different file formats

Is there a pattern that is good to use when saving and loading different file formats? For example, I have a complicated class hierarchy for the document, but I want to support a few different file formats. I thought about the Strategy pattern, but I'm not convinced because of the need to access every part of the object in order to sav...

How to properly handle exceptions when performing file io

Often I find myself interacting with files in some way but after writing the code I'm always uncertain how rubust it actually is. The problem is that I'm not entirely sure how file related operations can fail and, therefore, the best way to handle expections. The simple solution would seem to be just to catch any IOExceptions thrown by ...

Asynchronous file IO in .Net

I'm building a toy database in C# to learn more about compiler, optimizer, and indexing technology. I want to maintain maximum parallelism between (at least read) requests for bringing pages into the buffer pool, but I am confused about how best to accomplish this in .NET. Here are some options and the problems I've come across with ea...

How can I copy a large file on Windows without CopyFile or CopyFileEx?

There is a limitation on Windows Server 2003 that prevents you from copying extremely large files, in proportion to the amount of RAM you have. The limitation is in the CopyFile and CopyFileEx functions, which are used by xcopy, Explorer, Robocopy, and the .NET FileInfo class. Here is the error that you get: Cannot copy [filename]:...

Java .properties file equivalent for Ruby?

I need to store some simple properties in a file and access them from Ruby. I absolutely love the .properties file format that is the standard for such things in Java (using the java.util.Properties class)... it is simple, easy to use and easy to read. So, is there a Ruby class somewhere that will let me load up some key value pairs fr...

Preallocating file space in C#?

I am creating a downloading application and I wish to preallocate room on the harddrive for the files before they are actually downloaded as they could potentially be rather large, and noone likes to see "This drive is full, please delete some files and try again." So, in that light, I wrote this. // Quick, and very dirty System.IO.File...

DirectoryInfo.GetDirectories() and attributes

I am using DirectoryInfo.GetDirectories() recursively to find the all the sub-directories under a given path. How ever I want to exclude the System folders and there is no clear way for that. In FindFirstFile/FindNextFile things were clearer with the attributes. Thanks in advanced. ...

Letting several assemblies access the same text file

I've got many assemblies/projects in the same c#/.net solution. A setting needs to be saved by people using the web application gui, and then a console app and some test projects need to access the same file. Where should I put the file and how to access it? I've tried using "AppDomain.CurrentDomain.BaseDirectory" but that ends up being...

How to test for the EOF flag in R?

Hi all, How can I test for the EOF flag in R? e.g. f <- file(fname, "rb") while (???) { a <- readBin(f, "int", n=1) } Thanks. ...

xul: open a local html file relative to "myapp.xul" in xul browser

in short: is there any way to find the current directory full path of a xul application? long explanation: I would like to open some html files in a xul browser application. The path to the html files should be set programmatically from the xul application. The html files reside outside the folder of my xul application, but at the same...

Getting a FILE* from a std::fstream

Is there a (cross-platform) way to get a C FILE* handle from a C++ std::fstream ? The reason I ask is because my C++ library accepts fstreams and in one particular function I'd like to use a C library that accepts a FILE*. ...

Programmatically determine video file format?

Ok, I get the basics of video format - there are some container formats and then you have core video/audio formats. I would like to write a web based application that determines what video/audio codec a file is using. How best can I programmatically determine a video codec? Would it be best to use a standard library via system calls and...

Antivirus and file access conflict : good programming practices?

Sometimes, we experiment "access denied" errors due to the antivirus which handles the file at the same time our program wants to write/rename/copy it. This happens rarely but makes me upset because I don't find the good way to deal with: technically our response is to change our source code to implement kind of retry mechanism... but w...

Can the Java File method "canWrite()" support locking?

I have a Java application that monitors a folder for incoming XML files. When a new file is detected I need to test the file that it is not currently being updated and is closed. My thought is to use File.canWrite() to test this. Is there any issue with doing this? Is this a good way to test that a file has been completely written? ...

Using PL/SQL how do you I get a file's contents in to a blob?

I have a file. I want to get its contents into a blob column in my oracle database or into a blob variable in my PL/SQL program. What is the best way to do that? ...

How can I lock a file using java (if possible)

I have a java process that opens a file using a FileReader. How can I prevent another (java) process to open this file, or at least make that second process know that the file is already opened? Does this automaticaly makes the second process get an exception if the file is open(which solves my problem) or do i have to explicitly open it...

Ruby - Convert File to String

I need an easy way to take a tar file and convert it into a string (and vice versa). Is there a way to do this in Ruby? My best attempt was this: file = File.open("path-to-file.tar.gz") contents = "" file.each {|line| contents << line } I thought that would be enough to convert it to a string, but then when I try to write it back ou...

Web Log analysis in Java

Hello all, How to read a web server log file in Java. This file is getting updated all the time. If I open a new FileInputStream, will it read the log real time? Regards ...

What are possible reasons for java.io.IOException: "The filename, directory name, or volume label syntax is incorrect"

I am trying to copy a file using the following code: File targetFile = new File(targetPath + File.separator + filename); ... targetFile.createNewFile(); fileInputStream = new FileInputStream(fileToCopy); fileOutputStream = new FileOutputStream(targetFile); byte[] buffer = new byte[64*1024]; int i = 0; while((i = fileInputStream.read(buf...

Good ISAM library or other simple file manager for large files on Windows x64

Hi All We have some very large data files (5 gig to 1TB) where we need quick read/write access. Since we have a fixed record size it seems like some form of ISAM would be the way to go. But would be happy to hear other suggestions. Ideally the solution would have an Apache or LGPL style license but we will pay if we have to. Mus...