file-io

How do I use Java to read from a file that is actively being written?

I have an application that writes information to file. This information is used post-execution to determine pass/failure/correctness of the application. I'd like to be able to read the file as it is being written so that I can do these pass/failure/correctness checks in realtime. I assume it is possible to do this, but what are the gotch...

How to obtain good concurrent read performance from disk.

I'd like to ask a question then follow it up with my own answer, but also see what answers other people have. We have two large files which we'd like to read from two separate threads concurrently. One thread will sequentially read fileA while the other thread will sequentially read fileB. There is no locking or communication between ...

Java File IO Compendium

I've worked in and around Java for nigh on a decade, but have managed to ever avoid doing serious work with files. Mostly I've written database driven applications, but occasionally, even those require some file io. Since I do it so rarely, I end up googling around for quite some time to figure out the exact incantation that Java require...

How do I read in the contents of a directory in Perl?

How do I get perl to read the contents of a given directory into an array? Backticks can do it, but I know there is some method using 'scandir' or a similar term? ...

Is It Possible To Raise An Event When A File Becomes Accessible?

In C# I can use the FileSystemWatcher object to watch for a specific file and raise an event when it is created, modified, etc. The problem I have with this class is that it raises the event the moment the file becomes created, even if the process which created the file is still in the process of writing. I have found this to be very pr...

Access files from network share in c# web app

I have a web application that needs to read (and possibly write) files from a network share. I was wondering what the best way to do this would be? I can't give the network service or aspnet accounts access to the network share. I could possibly use impersonation. The network share and the web application are both hosted on the same do...

Why don't the std::fstream classes take a std::string?

This isn't a design question, really, though it may seem like it. (Well, okay, it's kind of a design question). What I'm wondering is why the C++ std::fstream classes don't take a std::string in their constructor or open methods. Everyone loves code examples so: #include <iostream> #include <fstream> #include <string> int main() { ...

Programmatically editing python source

This is something that I think would be very useful. Basically, I'd like there to be a way to edit python source programmatically without requiring human intervention. There are a couple of things I would like to do with this: 1) Edit the configuration of python apps that use source modules for configuration. 2) Set up a "template"...

How to discover a File's creation time with Java?

Is there an easy way to discover a File's creation time with Java? The File class only has a method to get the "last modified" time. According to some resources I found on Google, the File class doesn't provide a getCreationTime() method because not all file systems support the idea of a creation time. The only working solution I foun...

Reading text files using .NET

I need to read from a variety of different text files (I've some delimited files and some fixed width files). I've considered parsing the files line by line (slow using the File.ReadLine type methods) and reading the file using the ODBC text driver (faster) but does anyone have any other (better) suggestions? I'm using .NET/C#. ...

File Access Strategy in a Multi-Threaded Environment (Web App)

I have a file which is an XML representation of some data that is taken from a Web service and cached locally within a Web Application. The idea being is that this data is very static, but just might change. So I have set it up to cache to a file, and stuck a monitor against it to check if it has been deleted. Once deleted, the file will...

Why is my image coming out garbled?

I've got some Java code using a servlet and Apache Commons FileUpload to upload a file to a set directory. It's working fine for character data (e.g. text files) but image files are coming out garbled. I can open them but the image doesn't look like it should. Here's my code: Servlet protected void doPost(HttpServletRequest request, ...

How do I best generate a CSV (comma-delimited text file) for download with ASP.NET?

This is what I've got. It works. But, is there a simpler or better way? One an ASPX page, I've got the download link... <asp:HyperLink ID="HyperLinkDownload" runat="server" NavigateUrl="~/Download.aspx">Download as CSV file</asp:HyperLink> And then I've got the Download.aspx.vb Code Behind... Public Partial Class Download Inheri...

mmap() vs. reading blocks

I'm working on a program that will be processing files that could potentially be 100GB or more in size. The files contain sets of variable length records. I've got a first implementation up and running and am now looking towards improving performance, particularly at doing I/O more efficiently since the input file gets scanned many times...

Why does a "file exists" method in many languages return true for a directory?

I know that it does in PHP, and I'm pretty sure it does in Java. I haven't used the latest versions of .NET, so I won't speak for them. It seems very awkward, but I was wondering if there was an underlying reason for this. ...

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

Reading data from a log file as a separate application is writing to it.

I would like to monitor a log file that is being written to by an application. I want to process the file line by line as, or shortly after, it is written. I have not found a way of detecting that a file has been extended after reaching eof. The code needs to work on Mac and PC, and can be in any language, though I am most familiar with...

Can an fdopen() cause a memory leak?

I use fdopen to associate a stream with an open file. When I close() the file, is the stream automatically disassociated as well, and all stream memory returned to the OS, or do I need to be aware of the fdopen'd file and close it in a specific manner? ...

How can I use the PHP File api to write raw bytes?

I want to write a raw byte/byte stream to a position in a file. This is what I have currently: $fpr = fopen($out, 'r+'); fseek($fpr, 1); //seek to second byte fwrite($fpr, 0x63); fclose($fpr); This currently writes the actually string value of "99" starting at byte offset 1. IE, it writes bytes "9" and "9". I just want to write ...

Files on XP: Is turning off "last access time" safe?

I'm desperately looking for cheap ways to lower the build times on my home PC. I just read an article about disabling the Last Access Time attribute of a file on Windows XP, so that simple reads don't write anything back to disk. It's really simple too. At a DOS-prompt write: fsutil behavior set disablelastaccess 1 Has anyone ...