file-io

How do I specifiy a path to a file in Java?

Ok this is a homework questions, but I cannot find the answer anywhere, not even in the book. Path to Files If the user wants to specify a path for a file, the typical forward slash is replaced by ________. can you help? ...

Synchronization requirements for FileStream.(Begin/End)(Read/Write)

Is the following pattern of multi-threaded calls acceptable to a .Net FileStream? Several threads calling a method like this: ulong offset = whatever; // different for each thread byte[] buffer = new byte[8192]; object state = someState; // unique for each call, hence also for each thread lock(theFile) { theFile.Seek(whatever, See...

Reading Binary file in C

Hi All, I am having following issue with reading binary file in C. I have read the first 8 bytes of a binary file. Now I need to start reading from the 9th byte. Following is the code: fseek(inputFile, 2*sizeof(int), SEEK_SET); However, when I print the contents of the array where I store the retrieved values, it still shows me the ...

How to write an altered COM Structured Storage file to Disk?

I have a COM Structured Storage File reader implemented that can open Storage and stream objects, that's all happy. But now I want to be able to copy things from one archive to another and rename things and then write things back to the disk. I haven't even adressed the copy and rename operations because I can't seem to even write chan...

writing a data to App_Data

I want to write an .xml file using the following code into the App_Data/posts, why is it causing an error: Stream writer = new FileStream("..'\'App_Data'\'posts'\'" + new Guid(post_ID.ToString()).ToString() + ".xml", FileMode.Create); ...

fopen / fopen_s and writing to files

Hi, I'm using fopen in C to write the output to a text file. The function declaration is (where ARRAY_SIZE has been defined earlier): void create_out_file(char file_name[],long double *z1){ FILE *out; int i; if((out = fopen(file_name, "w+")) == NULL){ fprintf(stderr, "***> Open error on output file %s", file_name)...

Saving any file to in the database, just convert it to a byte array?

Is converting a file to a byte array the best way to save ANY file format to disk or database var binary column? So if someone wants to save a .gif or .doc/.docx or .pdf file, can I just convert it to a bytearray UFT8 and save it to the db as a stream of bytes? ...

Create all directories up to a point?

I need to be able to build all directories up to and including the directory specified by my File object. For example, suppose I have something like this: File file = new File( "/var/a/b/c/d/" ); But only /var/ exists. I need a method that builds up to d, and I was wondering if there was a method in a java io library somewhere that do...

visual c# open own file extention

hello everybody, first: i'm dutch so sorry if my english is not so good. I have made my own file type (.ddd) and I made a simple program to open this file type, but wenn i click on a .ddd file (on my desktop) my program opens only the file is not automaticly opend inside my program. how do I directly open the file in my program when ...

"Unable to open file", when the program tries to open file in /proc

Hi, I try to read file /proc/'pid'/status, using c program. The code is as follows, and even I use sudo to run it, the prompt still keeps throwing "Unable to open file". Please let me know if you have any ideas on how to fix this. thanks Richard ... int main (int argc, char* argv[]) { string line; char* fileLoc; if(ar...

File io error Python

I have a program that monitors a folder with word documents for any modifications made on the files. The error -Windows Error[2] The system cannot find the file specified- comes when I run the program, open a .doc within the folder make some changes and save it. Any suggestions on how to fix this? Edit1: the actual error code is like th...

How can get a filehandle for a Perl program's output?

I have an encrypted file X1, I have a Perl program P1 that decrypts the X1. I am parsing the decrypted file using a Perl program p2. X1--P1(decrypter) --> X2(plain text file) --p2(parser) --> parse output My parser is based on XML::Parser. It can work with a filehandle to the decrypted file. Now I am getting the X2 and storing it in t...

Traditional IO vs memory-mapped

I'm trying to illustrate the difference in performance between traditional IO and memory mapped files in java to students. I found an example somewhere on internet but not everything is clear to me, I don't even think all steps are nececery. I read a lot about it here and there but I'm not convinced about a correct implementation of neit...

Reading from a file, atoi() returns zero only on first element

Hi, I don't understand why atoi() is working for every entry but the first one. I have the following code to parse a simple .csv file: void ioReadSampleDataUsers(SocialNetwork *social, char *file) { FILE *fp = fopen(file, "r"); if(!fp) { perror("fopen"); exit(EXIT_FAILURE); } char line[BUFSIZ], *word, ...

C++ Pointer trouble with File I/O

Hi, I am writing a function that takes in a output target file and a couple of other arguments. I am currently having trouble with converting types between the argument passed in and using it in the fopen_s() method. FILE* outputf; void myfunc(FILE* fin, CString finpath,...) { outputf = fopen_s(&fin, finpath, "w"); ....... } I'...

Read whole ASCII file into C++ std::string

Hello, I need to read a whole file into memory and place it in a C++ std::string. If I were to read it into a char, the answer would be very simple: std::ifstream t; int lenght; t.open("file.txt"); // open input file t.seekg(0, std::ios::end); // go to the end length = t.tellg(); // report location (this is the leng...

Is it possible for competing file access to cause deadlock in Java?

I'm chasing a production bug that's intermittent enough to be a real bastich to diagnose properly but frequent enough to be a legitimate nuisance for our customers. While I'm waiting for it to happen again on a machine set to spam the logfile with trace output, I'm trying to come up with a theory on what it could be. Is there any way f...

.NET make a copy of an embedded file resource to the local drive

Hi, i'm new to the realm to working with Files in .NET I'm creating a WPF application in VB.NET with the 3.5 Framework. (If you provide an example in C#, that's perfectly fine.) In my project I have a Template for an MS Access database. My desired behavior is that when the users clicks File-->New, they can create a new copy of this t...

CFBundleDocumentTypes & UIFileSharingEnabled issues

Has anyone gotten UIFileSharingEnabled or CFBundleDocumentTypes to work? I added UIFileSharingEnabled as true to my plist and used Apple's example from the link below for CFBundleDocumentTypes, but can't seem to get it to work. I don't see my app under file sharing in iTunes, and I do not get the option to open documents I registered i...

'Programming by Coincidence' Excercise: Java File Writer

I just read the article Programming by Coincidence. At the end of the page there are excercises. A few code fragments that are cases of "programming by coincidence". But I cant figure out the error in this piece: This code comes from a general-purpose Java tracing suite. The function writes a string to a log file. It passes its...