file-io

Should I use a TMemoryStream as an efficient buffer before writing to a file?

Hi, I am using D6 Professional and need to create a text file in a specific format from lots of small strings already in memory. For performance reasons, I am considering using a TMemoryStream to collate the file data, and then write it out to disk in one go via a TFileStream. But I have a half forgotten memory (probably from pre-D6 da...

Using fseek to backtrack

Is using fseek to backtrack character fscanf operations reliable? Like for example if I have just fscanf-ed 10 characters but I would like to backtrack the 10 chars can I just fseek(infile, -10, SEEK_CUR) ? For most situations it works but I seem to have problems with the character ^M. Apparently fseek registers it as a char but fscan...

seek(), then read(), then write() in python

When running the following python code: >>> f = open(r"myfile.txt", "a+") >>> f.seek(-1,2) >>> f.read() 'a' >>> f.write('\n') I get the following (helpful) exception: Traceback (most recent ...

From C++ MD2 Loader to C\Objective-C & Cocoa.

It is mostly out of boredom, really... This afternoon I decided to make a simple 3D Game on Cocoa & OpenGL based on what I've done on one of my OpenGL class. I'm using the MD2 loading code that is posted at David Henry's "The Quake II's MD2 file format" and I like how it's put together, giving nice explanations, and nice C++ code. I wan...

Python - lines from files - all combinations

I have two files - prefix.txt and terms.txt both have about 100 lines. I'd like to write out a third file with the Cartesian product http://en.wikipedia.org/wiki/Join_(SQL)#Cross_join -about 10000 lines. What is the best way to approach this in Python? Secondly, is there a way to write the 10,000 lines to the third file in a rand...

Organizing files in "buckets"

My problem is like this: I have a written a client side HTTP cache and I need to store the HTTP payload in the file system somehow. I do not want to clutter the filesystem with unnecessary files. I have written this class: /* * Copyright (c) 2008, The Codehaus. All Rights Reserved. * * Licensed under the Apache License, Version...

Getting the inputstream from a classpath resource (XML file)

In Java web application, Suppose if I want to get the InputStream of an XML file, which is placed in the CLASSPATH (i.e. inside the sources folder), how do I do it? ...

Getting file names with scriptaculous.

I am looking to create basically an image rotator with scriptaculous. The trick is I want to use the images that are in a certain directory to drive the rotations. For Example if there are 3 files in the directory then it rotates with 3 images, 5 it will rotate five images. How can I read the file names to use/determine for Script...

How do you open and transfer a file on the filesystem in mod_python?

I'm new to mod_python and Apache, and I'm having trouble returning a file to a user after a GET request. I've got a very simple setup right now, and was hoping to simply open the file and write it to the response: from mod_python import apache def handler(req): req.content_type = 'application/octet-stream' fIn = open('response...

How to Perform Asynchronous File Reads in C# 2.0?

I have an application which needs to loop through all the lines in text files, over gigabytes in size. Some of these files have 10's or 100's of millions of lines. An example of my current (and synchronous) reading, looks something like... using (FileStream stream = new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.R...

How to output list of floats to a binary file in Python

I have a list of floating-point values in Python: floats = [3.14, 2.7, 0.0, -1.0, 1.1] I would like to write these values out to a binary file using IEEE 32-bit encoding. What is the best way to do this in Python? My list actually contains about 200 MB of data, so something "not too slow" would be best. Since there are 5 values, I ju...

Is there a way to get the PID from a process that is blocking a file using C#?

Is there a way to get the PID from a process that is blocking a file using C#? ...

Question about hard drive , 'seek' and 'read' in windows OS

Does anyone know when calling 'seek' and 'read' , how is the hard-drive physicly affected? If i'll be more specific, I know that the harddrive has some kind of a magnetic needle that is used to read the data from the magnetic plates. So my question is , when is the needle actualy moved to the reading location? Is it moved when we are c...

Multiple threads reading from the same file

My platform is windows vista 32, with visual c++ express 2008 . for example: 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 a example in C language. ...

C# 3.5 ASP.net File IO issue, UnauthorizedAccessException to file on network share

I get an UnauthorizedAccessException everytime I try to access (just read) a file on a network share "\\server\folder1\folder2\file.pdf." I am impersonating the domain\aspnet user which has read & write access to the above mentioned folders. The file is not read-only. I tried finding the permissions via System.Security.Permissions.F...

Most efficient way to make sure a line exists in a plain text file

I'm using C# (.Net 2.0), and I have a fairly large text file (~1600 lines on average) that I need to check periodically to make sure a certain line of text is there. What is the most efficient way of doing this? Do I really have to load the entire file into memory each time? Is there a file-content-search api of some sort that I could...

Is FileInfo.Copy accross network good solution? Is CAS required?

Seems that everything I do involves win services copying files across servers. I seem to get a lot of security & securityaccess type exceptions and never fully understand the causes. I am wondering if fileinfo or file.copy is a good solution or if there is a better. Is there a particular attribute I should be using or something to avoid ...

Reading data from UTF-8 text file and tokenize

I'm trying to read UTF-8 from a text file and do some tokenization, but I'm having issues with the encoding: try { fis = new FileInputStream(fName); } catch (FileNotFoundException ex) { //... } DataInputStream myInput = new DataInputStream(fis); try { while (thisLine = myInput.readLine()) != null) { StringTokeniz...

Parsing a textfile in C# with skipping some contents

Hi, I'm trying to parse a text file that has a heading and the body. In the heading of this file, there are line number references to sections of the body. For example: SECTION_A 256 SECTION_B 344 SECTION_C 556 This means, that SECTION_A starts in line 256. What would be the best way to parse this heading into a dictionary and then...

How to ignore hidden files with opendir and readdir in C library

Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur = readdir(pd)) puts(cur->d_name); What I get is kind of messy: including dot (.), dot-dot (..) and file names that end with ~. I want to do exactly the same thing as the command ls. How do I fix this, please? ...