file-io

File access speed vs database access speed

The site I am developing in php makes many MySQL database requests per page viewed. Albeit many are small requests with properly designed index's. I do not know if it will be worth while to develop a cache script for these pages. 1) Are file I/O generally faster than database requests? Does this depend on the server? Is there a way to ...

How do you get the size of a file in MATLAB?

What is the best way to figure out the size of a file using MATLAB? The first thought that comes to mind is size(fread(fid)). ...

How to filter a file using pattern to another file using Python?

I have a dictionary. I want to take only the words containing a simple word pattern (i.e. "cow") and write them to another file. Each line starts with a word and then the definition. I'm still extremely new at python so I don't have a good grasp of the syntax, but the pseudocode in my head looks something like: infile = open('C:/infile....

How to read path from a txt file and copy those file to a new directory?

from shutil import copy f = open(r'C:\temp.txt', 'r') for i in f.readlines(): print i copy(i,r"C:\opencascade") f.close() I am reading path from temp.txt file which has 500 lines each line is a path for specific file to be copied to location "C:\opencascade" How to convert 'i' in above code to be raw string to make the ...

Windows service can't copy to file share

I have a windows service set to copy files from a local directory to a samba share. The service connects via a UNC path to the server (i.e. \remoteserver\shareddir). I have logged in as the user under which the service is running, and was able to both copy files and create files on the samba share, using the UNC path. However, when ru...

What is the BEST way to replace text in a File using C# / .NET?

I have a text file that is being written to as part of a very large data extract. The first line of the text file is the number of "accounts" extracted. Because of the nature of this extract, that number is not known until the very end of the process, but the file can be large (a few hundred megs). What is the BEST way in C# / .NET to ...

File to byte[] in Java

What is the best way to convert a java.io.File to a byte[]? ...

Read vs. Write Times

Which operation is more time consuming - reading from a disk or writing to a disk for the same amount of data and the same memory location? ...

Accessing MP3 Player / USB Storage device

Hi I'm trying to access a USB Storage device, however the device although appearing in the commputer / Drives section, is not allocated a Drive letter, thus when I itterate through the attached drives link text it does not appear, I've taken the "Location" from a file on the drive (properties) and it comes up as COMPUTER/Q1/Datacasts bu...

More robust file system library in .net

Let me rephrase. My example probably wasn't good. A lot of things can go wrong when deleting a directory. A file has a readonly attribute set, the directory is opened by the windows explorer. I guess all of them can be handled - however I don't want to do it on my own - is there a wrapper that takes care of that with a simple api? I fin...

How do I write a float list of lists to file in Python

I need to write a series of matrices out to a plain text file from python. All my matricies are in float format so the simple file.write() and file.writelines() do not work. Is there a conversion method I can employ that doesn't have me looping through all the lists (matrix = list of lists in my case) converting the individual values...

Is there any better way to do filefilter for many ext?

File files[] = rootDir.listFiles(new FileFilter() { public boolean accept(File file) { if (file.isDirectory()) return true; String name = file.getName().toLowerCase(); if (name.endsWith(".zip") || name.endsWith(".jar") || name.endsWith(".z") || name.endsWith(".gz") || name.endsWith(".tar") || n...

When/why is it a bad idea to use the fscanf() function?

In an answer there was an interesting statement: "It's almost always a bad idea to use the fscanf() function as it can leave your file pointer in an unknown location on failure. I prefer to use fgets() to get each line in and then sscanf() that." Could you expand upon when/why it might be better to use fgets() and sscanf() to read some ...

Python: File IO - Disable incremental flush

Kind of the opposite of this question. Is there a way to tell Python "Do not write to disk until I tell you to." (by closing or flushing the file)? I'm writing to a file on the network, and would rather write the entire file at once. In the meantime, I'm writing to a StringIO buffer, and then writing that to the disk at the end. ...

How to unblock website which is blocked, using C#?

This is some code to unblock any website from listview, but now I want to unblock a website which has previously been blocked. How can I do this? String path = @"C:\Windows\System32\drivers\etc\hosts"; StreamWriter sw = new StreamWriter(path, true); String sitetoblock = "\n 127.0.0.1 http://"+listView1.SelectedItems[0].Text+""; sw.Write...

C# File.Open and Stream equivalent

Hi, This webservice expects this xml file: request.FeedContent = File.Open("test.xml", FileMode.Open, FileAccess.Read); I already have the file in a stream, but this statement hangs: stream.Position = 0; request.FeedContent = stream; the stream is a standard .net MemoryStream what operation do I do on the stream to make it the sa...

Java read file at a certain rate

Can someone point me to an article/algorithm on how can a read a long file at a certain rate? Say i do not want to pass 10 kb/sec while issuing reads. ...

Simple data storing in Python

I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed. I'm sure python has library for doing such a task easily but so far all the approaches I have found seemed like it would have been sloppy to get it to work and I'm sure there ...

Better approach for XML Creation in Blackberry

Hi there, I am facing a problem, I have created XML file,but I can't view it/output it.I know there is no way to output created XML file. Can anyone please suggest what is better way of creating xml files? 1) create xml with DocumentBuilderFactory and then parse it Or 2) manually create hardcoded xml and save it on sd card and then acce...

How can I read numbers from a file in Java?

How can I read inputs (letters, numbers) from my file.txt wherein it reads infinitely but only stops when it encounters special symbols? At the same time when it is numbers i.e 123,345,abc it should translate the ascii code and add the 2 values that results as 123 + 345 = 468 EDITED QUESTION Here's my code; I really had a problem wi...