file-io

(C# WinFoms) Writing files and New line...

Hi guys/gals, I'm making changes to a file, the 'source' file is a plain text file, but from a UNIX system. I'm using a StreamReader to read the 'source' file, I then make and store the changes to a StringBuilder using AppendLine(). I then create a StreamWriter (set-up with the same Encoding as the StreamReader) and write the file. N...

Read a text file from local folder

I want to read a text file from my local directory, I added the text file to my c# solution, so it would get copied at deployment.. but how do i open it? I've been searching but all the examples assume I have a C:\textfile.txt: I tried just reading the file if (File.Exists("testfile.txt")) { return true; } That didn't work. Then ...

C# IO Reading and Writing file in use error

I have a library that handles reading and writing a cache file. This library is used by a Windows Service and several instances of a console application on the same machine. The console application runs when a user logs in. I am getting occasional IO errors saying the cache file is in use by another process. I assume that collisions are...

How could I prevent a folder from being created using a windows service?

I have users and processes on a web server. I'm looking to write a windows service that is capable of intercepting calls to create folders within a specific sub-directory. I've found several sources out there for reactively catching that a folder was created, but I want to create a windows service that will proactively intercept and pre-...

How do I lock access to a file when a user has it open?

I'm writing a C#.NET program which uses XmlSerializer to serialize and deserialize the project the current user is working on to and from an XML file. This is working fine, but I'm trying to figure out a way to prevent two users from opening the same file off a network drive and having one user overwrite the previous user's save. I essen...

Remove and insert lines in a text file

I have a text file looks like: first line second line third line forth line fifth line sixth line I want to replace the third and forth lines with three new lines. The above contents would become: first line second line new line1 new line2 new line3 fifth line sixth line How can I do this using Python? ...

Ruby file IO delimiters?

I am trying to parse a text file that contains a variable number of words and numbers per line, like this: foo 4.500 bar 3.00 1.3 3 foo bar How can I read the file delimited by spaces instead of newlines? Is there some way I can set the File("file.txt").foreach method to use a spaces instead of newlines as a delimiter? ...

getResourceAsStream() vs FileInputStream

I was trying to load a file in a webapp, and I was getting a FileNotFound exception when I used FileInputStream. However, using the same path, I was able to load the file when I did getResourceAsStream(). What is the difference between the two methods, and why does one work while the other doesn't? ...

Python - Spaces in Filenames

Possible Duplicate: How to escape os.system() calls in Python? Is there a Python method of making filenames safe (ie. putting \ infront of spaces and escaping ( , ), symbols) programatically in Python? ...

Simple C++ input from file...how to?

I have a file: P 0.5 0.6 0.3 30 300 80 150 160 400 200 150 250 300 T r 45 0 0 s 0.5 1.5 0 0 t 200 –150 . . . When I read in 'P' I know that 3 floats will follow. That will be followed by a finite number of X and Y coordinates. The number will vary until a 'T' is reached which I have to recognize. Then there could be an 'r', 's' or 't...

In Java, how to read from a file a specific line, given the line number?

In Java, is there any method to read a particular line from a file, for example, read line 32? ...

Reusing a filestream

In the past I've always used a FileStream object to write or rewrite an entire file after which I would immediately close the stream. However, now I'm working on a program in which I want to keep a FileStream open in order to allow the user to retain access to the file while they are working in between saves. ( See my previous question)....

trouble writing to file in "for line in" iterator in Python script

This seems to be an embarrassingly simple question, but, after a day of reading over How-To's and manuals, it must be asked. I'm writing many lines to a few files using a few nested loops, inserting some static strings and copying lines over from other files over and over again. The output appears to be a single copy of the static strin...

istringstream - how to do this?

I have a file: a 0 0 b 1 1 c 3 4 d 5 6 Using istringstream, I need to get a, then b, then c, etc. But I don't know how to do it because there are no good examples online or in my book. Code so far: ifstream file; file.open("file.txt"); string line; getline(file,line); istringstream iss(line); iss >> id; getline(file,line); iss >> ...

IOError opening an existing file with Python

Running the following code: import os import datetime import ftplib currdate = datetime.datetime.now() formatdate = currdate.strftime("%m-%d-%Y %H%M") def log(): fqn = os.uname()[1] ext_ip = urllib2.urlopen('http://whatismyip.org').read() log = open ('/Users/admin/Documents/locatelog.txt','w') log.write(str("Asset: %s...

Loading the Biggest Numbered File into Memory

I have a directory in which filenames are entirely numbers. I want to find the highest valued number so that I can open that file and begin processing the data in the file. What would be the easiest way to go about this? My first blush idea is to load the directory of filenames into an array and iterate through the array looking to see w...

Java File I/O - Text File - How to check for content?

Hi guys, I was wondering, If i had a java class, that wanted to consult a txt file with say a list of names like tom steve jones how could i open the text file in the java program and basically see if a string contained in the program matches one of these names? so far i have come up with try { Buffer...

How to open a file stored in a server from aspx page using UNC share path?

I am listing the files stored in a remote server in the aspx page grid view with the file name linked (href) to the UNC path of the file. when the user clicks the file name link, it should open the file from the server to allow the user read the file. I am using impersonation (Using mirror logon method) for file upload and delete in the ...

Intercept file access on a network share in .NET

I am looking for a way to possibly intercept the point that a file is being accessed on a network share. Specifically before it is determined whether the user has access to the file or not. The goal will be to grant access to that file if the file request is coming from a specific process and that user currently does not have access. ...

Problems with File I/o when porting old 'C' libraries from 32-bit to 64-bit

I have really old 'c' code that uses read to read a binary file. Here is a sample: uint MyReadFunc(int _FileHandle, char *DstBuf, uint BufLen) { return (read( _FileHandle, DstBuf, BufLen)); } For 64bit OS - char * will be 64 bits but the BufLen is only 32 bits and the returned value are only 32 bits. Its not an option to...