file-io

FileInfo.Length is greater than 0 but File is Empty?

I have an application that crunches a bunch of text files. Currently, I have code like this (snipped-together excerpt): FileInfo info = new FileInfo(...) if (info.Length > 0) { string content = getFileContents(...); // uses a StreamReader // returns reader.ReadToEnd(); Debug.Assert(!string.IsNullOrEmpty(contents)...

Random Access files > 2GB with Android SDK

Hello, can anyone tell me how to random access a file beyond 2GB with android SDK. I was trying to seek to a position > 2147483647 and got the exception: "Value too large for defined datatype". That is odd as the parameter for the seek command is type "long". See the code example for details: RandomAccessFile BigFile; BigFile = new...

What's the best way to slurp the contents of a file into a string in Mathematica?

I know this is asked commonly but googling doesn't turn up a definitive answer for Mathematica so I thought it would be valuable to have this on StackOverflow. I've been doing this with Import but it occurred to me that that might be horribly inefficient, Import being such a heavyweight function. So the question is, can you improve on ...

Remove Duplicate ID's?

I have a list of 50,000 ID's in a flat file and need to remove any duplicate ID's. Is there any efficient/recommended algorithm for my problem? Thanks. ...

iReport: Repo file not found

I have a file located in my repo on JasperServer-side (delivery_settlement_files/delivery_list.jxml). But for some reason it continues to spit an error: Unable to locate the subreport with expression: ""repo:delivery_list.jrxml"". java.lang.Exception: repo:delivery_list.jrxml not found. It exists, but does not find. What could be...

How to create and read a file from spring web application running on JBoss?

I have a spring web application running on JBoss which is creating a csv file containing a report. The application must provide a link to the report when it finish its generation, and the user should be able to download it. I am thinking to write the file directly inside the war, so then we could read it from the web application. But I ...

Reading and Writing a new line from a file to another in Python

I'm trying to read from a file and write into another. The problem arises when I'm trying to preserve newlines from the original file to the new one. def caesar_encrypt(orig , shift): enctextCC = open("CCencoded.txt" , 'w') for i in range(len(orig)): for j in range(len(orig[i])): curr = orig[i][j] if ord(cu...

Parse and change a file line-by-line while preserving EOL characters in Java

One hell of a long question :) Here's how I usually do it: StringBuilder b = new StringBuilder(); BufferedReader r = new BufferedReader(new StringReader(s)); while ((String line = r.readLine()) != null) b.append(doSomethingToTheString(s) + "\n"); However, this replaces all the new line characters in the file with a line feed, plu...

What is the difference between .m and .mat files in MATLAB

When I traced my reference MATLAB script, I found files with the .mat extension. My questions are: What is the difference between .mat and .m files? How does one open files with the .mat extension? ...

C# get file change events

Hi, I do have a program which logs some specific events in a text file (it keeps the file open). Now I want to program a second application which shows these logs on a form. can I set an event for any change in a text file which is opened by another process? or I have to read that regularly? thanks ...

Strange behavior while listing directory contents using Java.io.File

Hi, (background) I'm using Java.io.File to do some windows directory searching. Basically the user inputs a directory path and I validate the path with file.isDirectory(). If the path is invalid I ask the user to re-enter a correct path. Once I get a valid directory I proceed with other File operations. (problem) Now the problem occurs...

Copying a list of paths/files to a directory

I'm just doing an exercise where I have a list of files (given as absolute paths), which should be copied to a given directory if some sort of flag is set. This is my function to copy the files: def copy_to(paths, dst): if not os.path.exists(dst): os.makedirs(dst) for path in paths: shutil.copy(path, dst) However, the giv...

How many open files in PHP?

Is there a function in PHP to query the number of open files? Sort of like memory_get_usage() but for open files. I'm running the unit test suites for Zend Framework. The problem is that after it gets through the tests for Zend_Search_Lucene, subsequent tests start failing. But if I skip the Zend_Search_Lucene tests, all the test s...

Cannot append to file when some other process writes to it on *nix systems

I have a very simple piece of code which just writes a small amount of data to a file at some regular interval. Once my program has created the file and appended some data, when I open this file in vim(or any other editor for that matter) and edit it, my process cannot seem to update the file anymore. I do not see any errors being return...

doubt in file path

i tried a program comparing C:\Program Files and C://Program Files i checked with compareTo()==0 it comes they are equal. But i doubt if there is any difference between //&\ Is there any difference? what is the difference between c:/program files and //? ...

how to access all filenames from a remote server folder - c#?

hi, I have many images on remote server say images.foo.com/222 & i want to access file names of all files that resides in the folder 222 on images.foo.com/. i have tried following code but getting error "virtual path is not valid" : imageserver = http://images.foo.com/222; DirectoryInfo di = new DirectoryInfo(imageserver); // line givin...

looking for an atomic/journaled page file in java

I am looking for an embeddable library for doing atomic file I/O from java. I need the library to support the following features. basic page management -- allocate/free pages and read/write atomic (all or nothing) writes (basically journaled I/O) A simple binary page format (needs to be readable by C++) It does not need to be that fas...

Getting the new line character without System.getProperty("line.separator")?

I want to create a text file, than load it up without any newlines or spaces (This is for a simple RPG). So I want to test for all 3 major OS line separators, and than the current OS'(s?) one. I know I can get the current one using System.getProperty("line.separator"), but how can I get Linux, Mac, and Windows line separators and turn ...

Is it faster to have more files in fewer folders, or more folders with fewer files?

Hey all. I'm creating an application that is going to be generating and storing millions of images. Before I start on this, I'm wondering if anyone knows if it's better to generate more folders and only keep a few files in each, or should I use a few folders and fill them up with lots of files? The generator will be written in C++ and...

Find all files in directory with extension .txt with python

How can I find all files in directory with the extension .txt in python? Thanks. UPDATE: Thanks everyone, wide variety of examples for the next person that searches for this. ...