io

How can I read an unsigned int from a binary file in Perl?

Lets say I have a binary file that is formatted like [unsigned int(length of text)][text][unsigned int(length of text)][text][unsigned int(length of text)][text] and that pattern for the file just keeps repeating. How in Perl do I read the unsigned int and print it out followed by the text block? Again, this is a binary file and not ...

Java: Use ObjectOutputStream without serializable

Hello, Sometimes, I want to use an ObjectOutputStream to write something to a file or sending a little image over the network. But BufferedImage and many other classes not implement java.io.Serializable and then the Stream cancels writing. Is there a way avoid that? Thanks, Martijn ...

Saving an Array to a Text file in Java

I'm trying to print the values of an int array to a local file. However, I can't seem to find a way to print the integers out in their standard form (1,2,3) instead of a heap address: ([I@1befab0) My code fragment is below: PrintWriter pr = new PrintWriter("file"); for (int i=0; i<views.length ; i++){ pr.pr...

Converting NSNumbers saved in a plist to integers

Saving data: - (NSString *)dataFilePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; return [documentsDirectory stringByAppendingPathComponent:kFilename]; } - (void)applicationWillTerminate:(NSNotification *)notification { NSMu...

How to retrive and download server files (File.Exists and URL)

Hi, I have a database table where the user marks files to be downloaded. Subsequently, I browse this table and need to create a fileList to pass to an ActiveX downloader. My routine works locally and on the server for ONLY the first file. I know my logic must be bad, but I cannot find it. All of these files are always in the same s...

Do I need to close() both FileReader and BufferedReader?

I'm reading a local file using a BufferedReader wrapped around a FileReader: BufferedReader reader = new BufferedReader(new FileReader(fileName)); // read the file // (error handling snipped) reader.close(); Do I need to close() the FileReader as well, or will the wrapper handle that? I've seen code where people do something like this...

How can I use Directory.GetFiles skipping UnauthorizedAccessException?

When I use System.IO.Directory.GetFiles method in C:\, an error is raised: Access to the path 'c:\System Volume Information' is denied. How can I handle that? ...

Why Java OutputStream.write() Takes Integer but Writes Bytes

I am writing an OutputStream, just noticed this in the OutputStream interface, public abstract void write(int b) throws IOException; This call write one byte to the stream but why it takes integer as an argument? ...

How do I read formatted input in Java?

Suppose my input file contains: 3 4 5 6 7 8 9 10 I want to run a while loop and read integers, so that I will get 3,4,5,6,7,8 and 10 respectively after each iteration of the loop. This is really simple to do in C/C++ but not in Java... I tried this code: try { DataInputStream out2 = new DataInputStream(new Buff...

Reading previous line of file with Ruby

How to read the prevous line of a file. The opposite of IO.gets.I initially thought to set IO.lineno to the line number I wanted to read but that doesn't work as expect. How do you actually read the previous line? ...

Reading previous line of file with Ruby

Using Ruby, I am reading a file line by line, using IO.gets to incrementally read the next line of the file. Under certain circumstances I want to do the opposite (look at the previous line by decrementing). The way I tried to accomplish this was... IO.lineno = int IO.gets It seems that no matter what I set "lineno" to equal it still ...

Detecting EOF in C

Hi, I am using the following code in C to take input from user until EOF occur, but problem is this code is not working, it terminate after taking first input. Anyone can tell me whats wrong with this code. Thanks in Advance. float input; printf("Input No: "); scanf("%f", &input); while(!EOF) { printf("Output: %f"...

buffered I/O vs unbuffered IO

Hi, I learnt that by default I/O in programs is buffered, i.e they are served from a temporary storage to the requesting program. I understand that buffering improves IO performance (may be by reducing system calls). An explanation on this will also help. Also I have seen functions say in C setvbuf to enable/disable buffering. I wanted ...

How to structure Haskell code for IO?

I'm trying to learn Haskell, so I decided to write a simple program to simulate the orbits of the planets around the sun, but I've run into a problem with printing out coordinates from the simulation, the top level function in my code is the following: runSim :: [Body] -> Integer -> Double -> [Body] runSim bodys 0 dtparam = bodys runS...

What is SQLite3 Disk I/O Error in Cocoa

I am programming in snow Leopard 10.6. My application opens up a locally stored database successfully, but when it tries to insert into the database, I continue to receive 'Disk I/O error". Anyone has any ideas as to what could possibly cause this? Thanks Yang ...

How to print an array to a .txt file in Matlab?

I am just beginning to learn Matlab, so this question might be very basic: I have a variable a=[2.3 3.422 -6.121 9 4.55] I want the values to be output to a .txt file like this: 2.3 3.422 -6.121 9 4.55 How can I do this? fid = fopen('c:\\coeffs.txt','w'); //this opens the file //now how to print 'a' to the file?? ...

Splitting huge file based on contents with ruby

Hi, Disclaimer: I'm not a programmer, never was, never learned algorithms, CS, etc. Just have to work with it. My question is: I need to split a huge (over 4 GB) CSV file into smaller ones (then process it with require 'win32ole') based on the first field. In awk it's rather easy: awk -F ',' '{myfile=$1 ; print $0 >> (myfile".csv")}' ...

Combining Multiple Files Into Single Archive (Silverlight/C#)

In Silverlight one does not have access to the entire .NET Library and therefore I am considering the best way to get the functionality I would have courtesy of System.IO.Packaging. I have multiple text files and I want to combine them into a single archive. Compression is not important but could wind up being valuable. By instinct I...

How to get the compressed image data from JPEG encoder in Java

I want to compress an image using JPEG encoder and instead of writing it to a file I want to pass the compressed data to another application. My problem is that I can compress the data but don't know how to get that compressed image data. I am using this code : out = new FileOutputStream ( filename ); JPEGImageEncoder encoder = JPEGCo...

What is in simple words blocking IO and non-blocking IO?

How would you explain a simple mortal about blocking IO and non-blocking IO? I've found these concepts are not very clear among many of us programmers. ...