fopen in various languages (file input/output

–C++
ofstream outfile(“out.txt”);
ifstream infile (“in.txt”); // class template

–C
FILE * pFile = fopen (“myfile.txt”,”w”);

–php follows C
<?php
$handle = fopen(“a.txt”, “r”);
?>

— python:
outfile = open(“a.txt”, “w”) # semicolon is usually omitted

–perl
open (OUTFILE, “>>append.txt”) or die …  ### No dollar sign. parentheses are optional but help readability

–c# offers many convenient solutions —
TextReader rd = new StreamReader(“in.txt”);
TextWriter tw = new StreamWrioter(“out.txt”);

Alternatively, File class offers variations of
static string ReadAllText(string path)
static void WriteAllText(string path, string contents) //creates or overwrites file

–java
I have written so many of them but paradoxically can’t recall which class we need to instantiate

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s