file-io

How can I set the file-read buffer size in Perl to optimize it for large files?

I understand that both Java and Perl try quite hard to find a one-size-fits all default buffer size when reading in files, but I find their choices to be increasingly antiquated, and am having a problem changing the default choice when it comes to Perl. In the case of Perl, which I believe uses 8K buffers by default, similar to Java's ...

Reliability of file locking on network files

I read that file locking on network files isn't very reliable. I'm using those LockFile/LockFileEx/UnlockFile win32-api functions for range-locks. Does anyone have some experience of using those functions on files living on a network-share? ...

Notify a Button if the number of files in a directory change

I have a button that I want to disable as long as there isn't a specific number of files in a directory. Is there some kind of listener that notifies me at the moment a file is created or deleted in a directory? ...

HA Tomcat file writing solution needed

We have a simple Webapp running on two Tomcat instances behind Apache (a Tomcat HA setup using mod_proxy_balancer and mod_proxy_ajp). The role of the webapp is to write incoming request data to a log file. Given that each tomcat instance is running in it's own JVM, how should we implement the log file writing? It would be excellent if ...

C#: How do I read a specified line in a text file?

Given a text file, how would I go about reading an arbitrary line and nothing else in the file? Say, I have a file test.txt. How would I go about reading line number 15 in the file? All I've seen is stuff involving storing the entire text file as a String array and then using the value of the line number as the number of the String to...

Multi threading in java

if i have a file contains 4000 bytes, can i have 4 threads read from the file at same time? and each thread access a different section of the file. thread 1 read 0-999, thread 2 read 1000 - 2999, etc. please give an example in java. ...

Write problem - lossing the original data

Every time I write to the text file I will lose the original data, how can I read the file and enter the data in the empty line or the next line which is empty? public void writeToFile() { try { output = new Formatter(myFile); } catch(SecurityException securityException) { System.err.println("E...

How to prevent file from being overridden when reading and processing it with Java?

Hi, I'd need to read and process somewhat large file with Java and I'd like to know, if there is some sensible way to protect the file that it wouldn't be overwritten by other processes while I'm reading & processing it? That is, some way to make it read-only, keep it "open" or something... This would be done in Windows environment. ...

What is an EOFError in Ruby file !/O?

The official documentation doesn't specify. I understand EOFError means "End of file error", but what exactly does that mean? If a file reader reaches the end of a file, that doesn't sound like an error to me. ...

Python looping to read and parse all in a directory

class __init__: path = "articles/" files = os.listdir(path) files.reverse() def iterate(Files, Path): def handleXml(content): months = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] parse = re.compile('<(.*?)>(.*?)<(...

StreamWriter .NET - how to get the best performance? C# .Net

What is the recommended approach to get the best performance when we need to create text files bigger than 10MB. There are multiple sections in the code that need to write stuff to a single file. This means a lot of text lines. Option #1: (This logic will be called at several times) Create a StreamWriter instance Write some lines (a...

What is the correct way to generate a json from file in GoogleAppEngine?

I'm quite new to python and GAE, can anyone please provide some help/sample code for doing the following simple task? I managed to read a simple file and output it as a webpage but I need some slightly more complicated logic. Here is the pseudo code: open file; for each line in file { store first line as album title; for eac...

Ruby: Search file text for a pattern and replace it with a given value?

Learning Ruby. I'm looking for a script to search a file (or list of files) for a pattern and, if found, replace that pattern with a given value. Thoughts? ...

UnauthorizedAccess Exception with File.Copy on a ReadOnly file

Simple question really... How can I copy a ReadOnly file? When running a debug build of my very simple Windows Forms app, I'm getting the UnauthoriazedAccess Exception when trying to copy a read-only file from one directory to another: FileInfo newFile = new FileInfo(fileName); File.Copy(newFile.FullName, Path.Combine(destinationDirPa...

Returning a stream directly to the web browser

I am generating a file on the server and I do not want to write it to disk but instead return it to the client via a web service. What recommendations would you have to do this? ...

MS Access Database query file path criteria in c#

I have an MS Access database that has Full paths to files in a table. We are moving all the file to a different location. I need to update the database. I'm using C# to do this. When I search for the file path stored in access it searches for 'K:\PDFFiles\myPDF.pdf' instead of 'K:\PDFFiles\myPDF.pdf' and does not find a match. So, my que...

C#: How to copy only the differences in a file from one directory to another

Say I have a big file in one directory and an older version of it in another. Is it somehow possible to update the older version with only the changes in the new one? So that I would copy only a small fraction from one place to another. Would have to work for both text and binary files. Not sure if this is possible though, but curious t...

Java: retrieve and replace the last line in a text file

What is the most efficient way of retrieving and replacing the last line of a text file (in Java 1.4) that could potentially contain millions of lines? Code examples I have seen so far have needed to iterate through the entire file line-by-line before determining if the last line was reached. A similar question was asked about replacing...

File Manipulation in C#

Hi, How do I check if the following statement in my C# executed correctly? StreamReader sr = new StreamReader(Path_To_File); ...

[Java] How to create tmp file name with out creating file.

I write application in Java using SWT. I would like to create unique file name. But I do not want create it on hard drive. Additional functionality: I want to create unique file name in specify folder. public String getUniqueFileName(String directory, String extension) { //create unique file name } ...