file-io

Java - get the newest file in a directory?

Does anybody have a snippet of Java that can return the newest file in a directory (or knowledge of a library that simplifies this sort of thing)? ...

How to read a line from file?

I have to read a txt file with lines formated like this: 1: (G, 2), (F, 3) 2: (G, 2), (F, 3) 3: (F, 4), (G, 5) 4: (F, 4), (G, 5) 5: (F, 6), (c, w) 6: (p, f), (G, 7) 7: (G, 7), (G, 7) w: (c, w), (c, w) Each line will feed a struct with its data (the 5 numbers or letters in it). What's the best way to read the line and get the strings ...

Inserting text into an existing file via Java

Hello, I would like to create a simple program (in Java) which edits text files - particularly one which performs inserting arbitrary pieces of text at random positions in a text file. This feature is part of a larger program I am currently writing. Reading the description about java.util.RandomAccessFile, it appears that any write ope...

C++ reading from a file blocks any further writing. Why?

I am implementing a very simple file database. I have 2 basic operations: void Insert(const std::string & i_record) { //create or append to the file m_fileStream.open(m_fileName.c_str(), std::ios::out | std::ios::app); if (m_fileStream.is_open()) { m_fileStream << i_record << "\n"; } m_fileStream.flush(...

Reading files larger than 4GB using c++ stl.

A few weeks back I was using std::ifstream to read in some files and it was failing immediately on open because the file was larger than 4GB. At the time I couldnt find a decent answer as to why it was limited to 32 bit files sizes, so I wrote my own using native OS API. So, my question then: Is there a way to handle files greater than ...

Handling an open file when trying File.Move()

Is this the best way to handle file moving in a windows service? we have many files that get matched and moved, but an end user may have the file opened at the time of moving. This is what the code currently says: Do While IO.File.Exists(OriginalFilePath) Try IO.File.Move(OriginalFilePath, BestMatchPath) Catch ex As IO.IO...

Open a file for shared writing

The following code is just a simplified example to demonstrate my problem: using System; using System.IO; using System.Diagnostics; using System.Threading; namespace ConsoleApplication5 { class Program { static string LogFile = @"C:\test.log"; static void Main(string[] args) { for (int i = 0...

Read a file from database

I have stored a txt file as string in a database coulum. Now on one of my aspx page I have a link...I want to open a txt file when the user clicks on this link. How can i read a file from database. I know how to do this using streamreader for a file stored on the disk. Thanks ...

How can I/O priority of a process be increased?

I want to increase the I/O priority of a process, both answers for .NET and windows vista would be nice... (or processexplorer is ok as well) ...

Write large file

I try to write to a large file, but it seems like it does not work for files larger than 2GB. I have tried with boost::iostreams::file_sink. Is this just a limit with the boost stream? Is there some other way I can write a large file on Win64 and win32? ...

If you had to add support for one video file format and codec, which would you choose?

I'm looking to add support for reading and writing video files in my application. If you had to choose exactly one file format and codec combination that would satisfy the majority of users, which would you choose: 1) MPEG-4/H.264 (.mp4) 2) AVI/DiVX (.avi) 3) Ogg/Theora (.ogg) 4) Windows Media Video (.wmv) I'm leaning towards MPEG-4/H...

C++ inserting a line into a file at a specific line number

I want to be able to read from an unsorted source text file (a record in each line), and insert the line/record into a destination text file by specifying the line number where it should be inserted. It will be determined where to insert the line/record into the destination file by comparing the incoming line from the source file to the...

Determining what process has a lock on a file

I have a unit test that works fine locally but when uploaded to TeamCity build server fails with "The process cannot access the file because it is being used by another process." Before I do anything in the Test I check in the setup if the file exists and if so try to delete it. This fails with the same error message as above When wri...

Quick file access in a directory with 500,000 files

I have a directory with 500,000 files in it. I would like to access them as quickly as possible. The algorithm requires me to repeatedly open and close them (can't have 500,000 file open simultaneously). How can I do that efficiently. I had originally thought that I could cache the inodes and open the files that way, but *nix doesn't...

problem with PHP reading CSV files

I'm trying to read data from a.csv file to ouput it on a webpage as text. It's the first time I'm doing this and I've run into a nasty little problem. My .csv file(which gets openened by Excel by default), has multiple rows and I read the entire thing as one long string. like this: $contents = file_get_contents("files/data.csv"); I...

Win32: Write to file without buffering ?

I need to create a new file handle so that any write operations to that handle get written to disk immediately. Extra info: The handle will be the inherited STDOUT of a child process, so I need any output from that process to immediately be written to disk. Studying the CreateFile documentation, the FILE_FLAG_WRITE_THROUGH flag looked...

How to fopen() on the iPhone?

The iPhone SDK docs claim fopen() is a supported method of file access but I am unable to get it to return a FILE handle. I am accessing a directory which is included in my project. I have tried fopen "filename","dir/filename","./filename","./dir/filename","/dir/filename" all returning with a null pointer. Some people report using it ...

C#: Side effects with Directory.GetFiles in a foreach statement and deleting files?

Hello, I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path, "*.txt")) { // do something, possibly delete the file named strFile } } Could there be side effects when deleting files in the directory that is currently used for the fo...

Is there an equivalent to the .Net FileSystemWatcher in the Linux world?

I find the .Net FileSystemWatcher class really handy for writing utilities that automatically come to life when files show up in their watched folders. Is there any equivalent to this functionality in the *nix world that would allow me to watch a folder (and possibly all of its subdirectories)? Edit: Preferably this will be something th...

Closing StreamReader after ReadToEnd

Is it possible somehow to close StreamReader after calling ReadToEnd method in construction like this: string s = new StreamReader("filename", Encoding.UTF8).ReadToEnd(); Any alternative elegant construction with the same semantics will be also accepted. Thanks! ...