Writing Files

So right now im using the arduino to generate random 8 bit numbers which are being output through serial port via Serial.print(). If the board can output to serial can that serial be written to a text file? I want the binary to be put to a text file so that i may read the file into a java or c program to convert the binary to decimal values for further processing. Ive seen file output with c but can it be done through serial?
#include <stdio.h>

int main(void)
{
char buffer[BUFSIZ];
char filename[] = "test.txt";
FILE *fp = NULL;

fp = fopen(filename, "w"); /* open file for reading */

if(fp == NULL) /* ALWAYS CHECK RETURN VALUE !!! /
{
printf("Failed to open file for writing\n");
return -1;
}
fputs("Hello world\n", fp); /
write a string to file /
fputc('A', fp); /
write a character to file /
fclose(fp); /
close file /
fp = fopen(filename, "a"); /
open file for appending !!! /
if(fp == NULL)
{
printf("Failed to open file for appending\n");
return -2;
}
fprintf(fp, "\nMy age is %d\n", 99); /
write a formatted string to file */
fclose(fp);

fp = fopen(filename, "r"); /* open file for reading */
if(fp == NULL)
{
printf("Failed to open file for reading\n");
return -3;
}
while(fgets(buffer, BUFSIZ, fp) != NULL)
printf(buffer);
fclose(fp);

return 0;
}
this is what i know to use for c output but this all doesnt work for the arduino ide so this is where i need help.

this is what i know to use for c output but this all doesnt work for the arduino ide so this is where i need help.

It doesn't work because the Arduino doesn't have a filesystem.
What do you want to write to file, and where do you want the file to end up?

I know you can write to an sd card but i do not have the appropriate device to connect the sd card to the board. Unless anyone can link me to how to connect the sd without a second interface board i would like to write the file to my laptop hard drive

GoBetwino can do it for you.

At least if you do not need breakneck speed.
And you will need to convert your data to a string of some kind.

You can use serial.print to send datas over serial connection.

So from, you can write a program (c language or other), that reads datas from the serial port and display the results you want to your computer.

Another way is to use an lcd connected to the arduino to display the results.

I bought this one and is very good one :

http://www.nuelectronics.com/estore/index.php?main_page=product_info&cPath=1&products_id=12

I like the idea of having a program reads the serial output and in java i know how to read and write files but how does one read from the serial box? I can see making a java program that reads the serial box until the box closes that read wouldnt be hard but how do you actually read from the serial box?

I know how to do this on Linux and Windows by using C language. But no with java...

Check on google to find samples of code. It must be not so complicated IMHO...

A good doc to start : http://www.google.fr/url?sa=t&source=web&cd=2&ved=0CCIQFjAB&url=http%3A%2F%2Fjava.sun.com%2Fdeveloper%2FBooks%2Fjavaprogramming%2Fcookbook%2F11.pdf&ei=D0G5TYGzOsS5hQfRvbCaAw&usg=AFQjCNF4a3nQ4DDYg6_n5hXKoiSV3TDuzw

I don't think you have to read from the serial monitor window, if that's what you're envisioning. I believe that if you don't open the serial monitor window, your host PC won't have the COM port open, so you can open it from another program written in C or Java or , then read from the port and you will receive whatever you present to Serial.print() on the Arduino side.