file-io

Downloading an image, want to save to folder, check if file exists

So I have a recordset (sqlalchemy) of products that I am looping, and I want to download an image and save it to a folder. If the folder doesn't exist, I want to create it. Also, I want to first check if the image file exists in the folder. If it does, don't download just skip that row. /myscript.py /images/ I want the images folde...

Noob question, passing in a file name / directory into command line in Java

I'm trying to do some processing on whether the user enters a (1) file name, or (2) directory name into the command line. Anything else should throw an error. Starting with the simplest case, I wrote this: import java.io.*; import java.util.*; public class RemoveDuplicates { public static void main(String[] args) { if (a...

Splitting text by newline character "\n" in Adobe AIR

Hi guys, I am creating a AIR application in flex. I have a textArea having a string something like - AAA BBB CCC DDD QQQ WWW EEE SSS KKPPP SSSL AAAS I want this to save this into .txt file. I am using - file.save(output.text,"testFile.txt"); But its is saving everything in 1 line. When I open the file using notepad everything i...

file pointer and using fgets

Hello, gcc 4.4.4 c89 I am reading in a file and in that file I have to do some operation on each line. In a loop I call a 2 functions that pass in this file pointer to perform 2 different operations on the file. However, as I am using fgets to read in a line of that text file. It automatically increments to the next line. So for the ...

Where to place test files for unit testing

I am writing some units tests and I need to be able to access an external file. I assumed I could just place the file in my solution, mark it to be copied to the output directory, and then access it via a relative path. Unfortunately it seems that unit tests are run in a strange directory. So, instead of running from: "[MyUnitTestProj...

Reading from file

I am a beginner and just started learning Python couple days ago (yay!) so i've come across a problem. when i run, this code outputs everything but the text (txt in file is numbers 0-10 on seperate lines) def output(): xf=open("data.txt", "r") print xf print("opened, printing now") for line in xf: print(xf.read(...

Keeping track of punctuation, spacing, when editing a file in Java

I'm writing a program to delete duplicate consecutive words from a text file, then replaces that text file without the duplicates. I know that my current code does not handle the case where a duplicate word is at the end of one line, and at the beginning of the next line since I read each line into an ArrayList, find the duplicate, and ...

ASP.NET MVC FileContentResult SLOW

We are using it to return a file for an export. When we run this export on a lot of records, it takes close to 10 minutes to run. Here is a code snippet of the code that actually calls the File() method and returns the result. Public Function Export(ByVal ID As Integer) As FileContentResult Dim str As String = String.Empty Dim data(...

Best way to parse a large floating point file stored in ascii?

What would be the fastest way to do it? I remember someone telling me using ifstream was bad because it worked on a small number of bytes, and it would be better to just read the file into memory first. Can anyone confirm this? Thanks Edit: I am running on windows, and the file format is for a point cloud that is stored in rows like ...

Does a Stream from a file contain the source file's attributes?

I'm trying to understand how File attributes such as the Created and Modified dates relate to a System.IO.Stream or System.IO.FileStream to the file. Are these attributes contained in the stream, or is the data part of the file that is read by the Stream separate from the file attributes? ...

What is simplest way to read a file into String in java

I am trying to read a simple text file into a String. Of course there is the usual way of getting the input stream and iterating with readLine() and reading contents into String. Having done this hundreds of times in past, I just wondered how can I do this in minimun lines of code? Isn't there something in java like String fileContents...

How do I truncate a file X bytes from the end?

Lets say there is a file which is 150 bytes long and I want to truncate the last 16 (or any number) of it from the end... Is there any other way to do it than re writing the complete file? UPDATE: The SetLength should do the thing, but unfortunately NotSupportedException is thrown using (FileStream fsFinalWrite = new FileStream(File...

Python method for storing list of bytes in network (big-endian) byte order to file (little-endian)

My present task is to dissect tcpdump data that includes P2P messages and I am having trouble with the piece data I acquire and write to a file on my x86 machine. My suspicion is I have a simple endian-ness issue with the bytes I write to to file. I have a list of bytes holding a piece of P2P video read and processed using python-pcapy...

Why does my program read an extra structure?

Hi all. I'm making a small console-based rpg, to brush up on my programming skills. I am using structures to store character data. Things like their HP, Strength, perhaps Inventory down the road. One of the key things I need to be able to do is load and save characters. Which means reading and saving structures. Right now I'm just savi...

open O_CREAT | O_EXCL on NFS in Linux?

When in the Linux 2.6 kernel and in NFSv3 did open("fname", O_CREAT|O_EXCL) became valid? The current canonical open(2) system call documentation (http://www.kernel.org/doc/man-pages/online/pages/man2/open.2.html) says everything is fine: O_EXCL ... On NFS, O_EXCL is only supported when using NFSv3 or later on kernel 2.6 or later. I...

Locking a file for an individual Thread within a VM.

Hello, I have multiple threads which are serializing my 'Data' objects to files. The filename is based on 2 fields from the Object class Data { org.joda.DateTime time; String title; public String getFilename() { return time.toString() + '_' + title + ".xml"; } It is possible that 2 Data objects will have the...

Writing binary data to middle of a sparse file in Python

I need to compile a binary file in pieces with pieces arriving in random order (yes, its a P2P project) def write(filename, offset, data) file.open(filename, "ab") file.seek(offset) file.write(data) file.close() Say I have a 32KB write(f, o, d) at offset 1MB into file and then another 32KB write(f, o, d) at offset ...

setting file encodings transferring data via send_data in Rails

Hi, I'd like to transfer a UTF-8 encoded string to the client, rendering the string as a text file (in my case a v-card) using send_data str, :filename => "file.vcf", :type => 'text/html; charset=utf-8' Unfortunately the submitted file doesn't contain any encoding information and address books open the file in the default encoding o...

Python: Checking if new file is in folder

Hi, I am relatively new to python, but I am trying to create an automated process where my code will listen for new file entries in a directory. For example, someone can manually copy a zip file into a particular folder, and I want my code to recognize the file once it has completely been copied into the folder. The code can then do som...

Read lines in Java ME

Does Java ME allow you to read a line from an InputStream? ...