file-io

Does StreamWriter work inconsistently with relative paths?

I am trying to save a LINQ XML document using a StreamWriter. Using the following code works fine when the document is small (~6kb on disk) but doesn't work when the file is larger (~66kb on disk). If I replace the relative path with an absolute path it works fine in both situations. Is there any reason why the relative path should fail ...

Write to a Directory as a Specific User on a Different Domain

Hi All, I am wondering, how would one write a file (say for instance, from a Console Application in a scheduled task) to another computer on a different domain? How would one set the Username and Password, such as with the "Log on to..." dialog to authenticate? Couple of prerequisites exist, obviously: The machines can see each other...

modify file content

I'm installing a lighttpd server on a remote machine using a bash script. After installation, I need to configure the port for the server. The system says I don't have permission to modify the file /etc/lighttpd/lighttpd.conf even though I do sudo echo "server.bind=2000" >> /etc/lighttpd/lighttpd.conf How shall I modify this? ...

select() for multiple file I/O in C#?

Is there functionality in C# standard libraries analogous to select()? In particular, the C# program needs to block waiting on I/O events of multiple file streams (not sockets). Thanks. ...

How can I select a random name from a list and store it in a variable?

Hello, I'm already developing that project to my family, but now i'm needing to link a Name to another aleatory(remember that the first name i have it) and store only the second name in a variable, remember that this list is a file(*.txt) with some names, but how i can do this? Thanks. ...

How to assign a value to an enum based on input from a file in C++?

I have a file with values like: START and STOP. I also have the following enum declared: enum Type { START, STOP }; I'm trying to set the enum equal to the first value in the file with something like this: enum Type foo; ifstream ifile; ifile.open("input.txt"); ifile >> foo; I'm getting the error: no match for ‘operator>>...

Is it possible to save arbitrary data to a file in C#?

I have a class with many collections loaded in memory. Is it possible to some how save this class with all its data to a file to be able to simply reload it to memory later? Is there an interface that would handle all this? ...

java.nio.BufferUnderflowException when processing files in Scala

I got a similar problem to this guy while processing 4MB log file. Actually I'm processing multiple files simultaneously but since I keep getting this exception, I decide to just test it for a single file: val temp = Source.fromFile("./datasource/input.txt") val dummy = new PrintWriter("test.txt") var itr = 0 println("Default Buffer siz...

Open/close strategy for /proc pseudo-file

I have written a C utility for Linux that checks the contents of /proc/net/dev once every second., I open the file using fopen("/proc/net/dev", "r") and then fclose() when I'm done. Since I'm using a 'pseudo' file rather than a real one, does it matter if I open/close the file each time I read from it, or should I just open it when my ...

How to append text to an existing file in Java

I need to append text repeatedly to an existing file in Java. How do I do that? ...

Whitespace at end of file causing EOF check to fail in C++

I'm reading in data from a file that has three columns. For example the data will look something like: 3 START RED 4 END RED To read in the data I'm using the following check: while (iFile.peek() != EOF) { // read in column 1 // read in column 2 // read in column 3 } My problem is that the loop usually does on extra ...

Read numbers and Convert them into doubles?

Okay, so i have a fairly annoying problem, one of the applications we use hdp, dumps HDF values to a text file. So basically we have a text file consisting of this: -8684 -8683 -8681 -8680 -8678 -8676 -8674 -8672 -8670 -8668 -8666 -8664 -8662 -8660 -8657 -8655 -8653 -8650 <trim... 62,000 more rows> Each of these represent a double:...

Command-Line App Read from File in C#

I am writing a small command-line tool for my own daily tasks, and having problems reading from a XML file I have used for configuration. As per the examples, I use this code to load the XML file for Linq-to-XML. XDocument doc = XDocument.Load("SearchSources.xml"); What I'm having problems with is when I "deploy" my app and XML t...

Python File Slurp

Is there a one-liner to read all the lines of a file in Python, rather than the standard: f = open('x.txt') cts = f.read() f.close() Seems like this is done so often that there's got to be a one-liner. Any ideas? ...

Accessing a single file with multiple threads

I need to access a file concurrently with multiple threads. This needs to be done concurrently, without thread serialisation for performance reasons. The file in particular has been created with the 'temporary' file attribute that encourages windows to keep the file in the system cache. This means most of the time the file read wont go ...

ANSI C getc causes segfault on Linux but not OS X

I have some ANSI C code that I developed on my Mac, but when I tried running it on our school's Linux servers I get a segfault. The specific line that is causing me trouble is a getc from a file pointer. The file does exist. Here is the method in question: // inits lists with all data in fp file pointer // returns # of lines read int...

PHP and file manipulation

I was wondering if it is possible to open an xml file as a plain text file so I can read in each line and manipulate the text? ...

[APUE]Does parent and child share the same file offset after fork?

In APUE section 8.3 fork function, about file sharing between parent and child processes, It said: It is important that the parent and the child share the same file offset. And in section 8.9 Race Conditions, there is a example: both parent and child write to a file which is opened before invoking fork function. The program contains a...

In Cocoa, how do you change the line endings of a file to LF?

Do I have to read the files and iterate manually? I'd like to be able to change between LF and CRLF. ...

How are files validated when opened?

Suppose a user selects a file in a dialogue box, and the app then opens the file for reading, etc. Users can open "incorrect" files--they can select a binary file, for example, even if the file they're supposed to be selecting is a text file. I recognize that sometimes improper file types generate exceptions, which can be handled. But ...