View Single Post
Old Jan 18th, 2008, 6:40 AM   #4
domquem
Newbie
 
Join Date: Jun 2005
Posts: 7
Rep Power: 0 domquem is on a distinguished road
Send a message via Yahoo to domquem
Re: Reading Files in Java problem

this is what i have managed to pull.

import java.io.*;
class FileRead
{
public static void main(String args[])
{
try{
// Open the file that is the first command line parameter
FileInputStream fstream = new FileInputStream("a.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
class FileWrite
{
public static void main(String args[])
{
try{
// Create file
FileWriter fstream = new FileWriter("write_me.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("create new file and write into it!!/n");
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
domquem is offline   Reply With Quote