file-io

Efficient way to delete a line from a text file

I need to delete a certain line from a text file. What is the most efficient way of doing this? File can be potentially large(over million records). UPDATE: below is the code I'm currently using, but I'm not sure if it is good. internal void DeleteMarkedEntries() { string tempPath=Path.GetTempFileName(); using (var reader = new...

Performance / stability of a Memory Mapped file - Native or MappedByteBuffer - vs. plain ol' FileOutputStream

I support a legacy Java application that uses flat files (plain text) for persistence. Due to the nature of the application, the size of these files can reach 100s MB per day, and often the limiting factor in application performance is file IO. Currently, the application uses a plain ol' java.io.FileOutputStream to write data to disk. ...

How can I determine the content type of a file in .NET?

I'm given a filename and I have to be able to read it from disk and send its contents over a network. I need to be able to determine whether the file is text or binary so I know whether to use a StreamReader or BinaryReader. Another reason why I need to know the content type is because if it is binary, I have to MIME encode the data be...

Binary Search for a line in a text file using Javascript

Is there a way to do a disk-based binary search for a particular key in a text file in Javascript? The text file is too big to be loaded into memory, but sorted by the key values. In particular I am looking for a way to mimic Perl's Search::Dict functionality in Javascript. For e.g. If I have a file foo.txt: a 1 b 10 c 5 z 4 look(c,f...

Exception when ASP.NET attempts to delete network file.

Greetings - I've got an ASP.NET application that is trying to delete a file on a network share. The ASP.NET application's worker process is running under a domain account (confirmed this by looking in TaskManager and by using ShowContexts2.aspx¹). I've been assured by the network admins that the process account is a member of a group t...

Check For File Lock Without A Try Catch

Is there a better way to check if a file is not locked then to open the file to catch an exception. I have a filewatcher running on a directory and I need to do something to the file after the file has completely moved/created in the location. Aren't throwing an exception a performance hit? Is there a better way? Private Function FileAv...

C++ File Handling

I Googled around, but didn't find any good example / tutorial. So i asking you SOF: How do you Read and Write to a File in C++? ...

C++ fstream error

I learning c++, started learning File Handling today. but getting a error when runinng this code #include <iostream> #include <fstream.h> using namespace std; int main() { fstream file; file.open("test.txt",ios::in|ios::out) file.close(); return 0; } Gets error Cannot open include file...

Java: Reading the Trailing New Line from a Text File

How can you get the contents of a text file while preserving whether or not it has a newline at the end of the file? Using this technique, it is impossible to tell if the file ends in a newline: BufferedReader reader = new BufferedReader(new FileReader(fromFile)); StringBuilder contents = new StringBuilder(); String line = null; while...

PHP standard input?

I know PHP is usually used for web development, where there is no standard input, but PHP claims to be usable as a general-purpose scripting language, if you do follow it's funky web-based conventions. I know that PHP prints to stdout (or whatever you want to call it) with print and echo, which is simple enough, but I'm wondering how a P...

Multiple output files

edit: Initially I was trying to be general but it came out vague. I've included more detail below. I'm writing a script that pulls in data from two large CSV files, one of people's schedules and the other of information about their schedules. The data is mined and combined to eventually create pajek format graphs for Monday-Sat of peop...

Convert MemoryStream to FileStream creates hundreds of identical files?

I am accessing a httpwebrequest that returns a pdf file as the response. I am reading that response into a memory stream, and later on converting to a file. The problem is, is that hundreds of files are being created. Not sure why, I've tried many ways, and all do the same... This is the first method which returns the memorystream. ...

Will calling a File.Exist put a lock on a file?

Hi, If I am trying to delete a file, but at the same time another process is performing a File.Exists(...) on the same file, will that potentially lock the file and cause my process to fail? ...

Java IO implementation of unix/linux "tail -f"

I'm wondering what techniques and/or library to use to implement the functionality of the linux command "tail -f ". I'm essentially looking for a drop in add-on/replacement for java.io.FileReader. Client code could look something like this: TailFileReader lft = new TailFileReader("application.log"); BufferedReader br = new BufferedRea...

Serialization byte array vs XML file

Hello, I am heavily using byte array to transfer objects, primitive data, over the network and back. I adapt java's approach, by having a type implement ISerializable, which contains two methods, as part of the interface, ReadObjectData and WriteObjectData. Any class using this interface, would write date into the byte array. Something...

How do I serve a large file for download with Perl?

I need to serve a large file (500+ MB) for download from a location that is not accessible to the web server. I found the question Serving large files with PHP, which is identical to my situation, but I'm using Perl instead of PHP. I tried simply printing the file line by line, but this does not cause the browser to prompt for download...

Writing ALL program output to a txt file in C++

Hi, I need to write all my program output to a text file. I believe it's done this way, sOutFile << stdout; where sOutFile is the ofstream object that creates the file like this: sOutFile("CreateAFile.txt" ); // CreateAFile.txt is created. When I insert the stdout into the sOutFile object, I get some code which seems to resemble ...

How do I skip reading a line in a file in C++?

The file contains the following data: #10000000 AAA 22.145 21.676 21.588 10 TTT 22.145 21.676 21.588 1 ACC 22.145 21.676 21.588 I tried to skip lines starting with "#" using the following code: #include <iostream> #include <sstream> #include <fstream> #include <string> using namespace std; int main() { while( getline...

Open Excel file for reading with VBA without display

I want to search through existing Excel files with a macro, but I don't want to display those files when they're opened by the code. Is there a way to have them open "in the background", so to speak? ...

Exception when destroying TReader

The following code throws an EZDecompressionError with message 'Invalid ZStream operation' whenever the line Reader.Free is executed. Can someone tell me what's wrong with this code? Reader := nil; Decompressor := nil; InputFile := TFileStream (FileName, fmOpenRead); try Decompressor := TDecompressionStream.Create (InputFile); Re...