io

How to read a text file upto certain position in C?

I am passing a string as an argument to my program and extracting its position in a text file. Can we read a text file only upto this certain position in C?? If yes, then please tell me how. ...

Reading binary files, Linux Buffer Cache

I am busy writing something to test the read speeds for disk IO on Linux. At the moment I have something like this to read the files: Edited to change code to this: const int segsize = 1048576; char buffer[segsize]; ifstream file; file.open(sFile.c_str()); while(file.readsome(buffer,segsize)) {} For foo.dat, which is 150GB...

What are the consequences of calling write() with zero length?

At fairly high level in the Linux write() function, it filters out requests for writing 0 length buffers. Which makes sense. Who'd want to the OS wasting it's time drilling through layers only to determine there is no work to be done? Well ... me. It's related to this question; and the discovery that the bit-banged I2C driver will g...

Blocking file-read in php?

I want to read everything from a textfile and echo it. But there might be more lines written to the text-file while I'm reading so I don't want the script to exit when it has reached the end of the file, instead I wan't it to wait forever for more lines. Is this possible in php? ...

watch / read a growing log file with ruby

I have a log file that is constantly growing, how can I watch and parse it via a ruby script. The script will parse each new line as it is written to the file and output something to the screen when the new line contains the string 'ERROR' ...

Why are there no simple IO utils in the JDK for reading an entire file into a String?

In the comments to my answer about reading an entire file into memory using scala.io.Source, I asserted that the reason there is no read-whole-file-into-String method in Java is that it is not (of course) scalable with regards to how big the file is and how much heap you have. However, I guess everyone has some method like: String con...

Designing efficient C++ code for fibers

How do I utilize fibers best in my game code? Should it only be used to manage nonpreemptive context-switches while loading resources (i.e. files from disk)? Or do I allow all types of game entities to run in a fiber? How do I schedule? C++ or pseudo code samples greatly appreciated! ...

Java: ignoring an input stream - will buffers overflow and bad things happen?

Hi all, I have a client connecting to my server. The client sends some messages to the server which I do not care about and do not want to waste time parsing its messages if I'm not going to be using them. All the i/o I'm using is simple java i/o, not nio. If I create the input stream and just never read from it, can that buffer fill...

how to read numbers from an ascii file (C++)

i need to read in data files which look like this: * SZA: 10.00 2.648 2.648 2.648 2.648 2.648 2.648 2.648 2.649 2.650 2.650 2.652 2.653 2.652 2.653 2.654 2.654 2.654 2.654 2.654 2.654 2.654 2.654 2.654 2.655 2.656 2.656 2.657 2.657 2.657 2.656 2.656 2.655 2.655 2.653 2.653 2.653 2.654 2.658 2.66...

Java I/O consumes more CPU resource

I am trying to create 100 files using FileOutputStream/BufferedOutputStream. I can see the CPU utilization is 100% for 5 to 10 sec. The Directory which i am writing is empty. I am creating PDF files thru iText. Each file having round 1 MB. I am running on Linux. How can i rewrite the code so that i can minimize the CPU utilization? ...

Check if directory exists in lua?

How do I check if a directory exists in lua, preferably without using the LuaFileSystem module if possible? Trying to do something like this python line: os.path.isdir(path) ...

Groovy way to log process output

I would like to start a long-running command-line process in my Grails application, log each line of output to the console when it arrives, and do other stuff asynchronously, while the process and logging activities keep going. (At some point, I'll want to do something else with each line of output, like log to a file or look for certain...

What is the fastest way to read 10 GB file from the disk?

We need to read and count different types of messages/run some statistics on a 10 GB text file, e.g a FIX engine log. We use Linux, 32-bit, 4 CPUs, Intel, coding in Perl but the language doesn't really matter. I have found some interesting tips in Tim Bray's WideFinder project. However, we've found that using memory mapping is inherent...

Java temp files and automated deletion

It is safe to use java's createTempFile method to create a temp file and then rename it and keep it as a permanent file? Or does java or the system in some way keep track of its temporary files and delete them at some point? btw..this is related to Mac OS X specifically. ...

Copy a changing file with File.Copy

Hi, I'm writing some sort of backup tool that has to copy all the files in a directory. Now I'm using C#'s File.Copy(String, String, Boolean) method. But another application (which I can't change) simultaneously writes to the files in that directory. So now I wonder if it is possible that a file gets changed halfway the copying process...

efficient and flexible binary data parsing

I have an external device that spits out UDP packets of binary data and software running on an embedded system that needs to read this data stream, parse it and do somethign useful. The binary data gets logged to a file as well. I would like to write a parser that can easily take the input directly from either the UDP stream, or a file...

How can I simulate a failed disk during testing?

In a Linux VM (Vmware workstation or similar), how can I simulate a failure on a previously working disc? I have a situation happening in production where a disc fails (probably a controller, cable or firmware problem). Obviously this is not predictable or reproducible, I want to test my monitoring to ensure that it alerts correctly. I...

Remove line from big txtfile in Java

Hello, Does anybody know how to remove a line from a textfile. I'm looking for something else than u read and write line by line and skip the line you want te remove. For exemple: My File count 1346 lines and I want to remove line 520. Thanks, Martijn ...

python file-like buffer object

I've written a buffer class that provides a File-like interface with read, write, seek, tell, flush methods to a simple string in memory. Of course it is incomplete (e.g. I didn't write readline). It's purpose is to be filled by a background thread from some external data source, but let a user treat it like a file. I'd expect it to cont...

Reading ints from file with C

Hello. This is a very simple question, but I can't seem to find something about it in here already. I want to read two integers from a file with C. My code now is this: int main() { FILE *fp; int s[80]; int t; if((fp=fopen("numbers", "r")) == NULL) { printf("Cannot open file.\n"); } else { fscanf(fp,...