mmcnitt
11-04-2009, 05:15 AM
I'm making a login applet and i can get it to output the information necessary to a file, and i can get it to input all the information from the file for me. However i can't seem to find out how to make it search the file for the information.
I don't wish to show my code, but here's basically the output input method i'm using
import java.io.*;
public class OutputInput
{
// Main method
public static void main (String args[])
{
try
{
// Open an output stream
FileOutputStream fout = new FileOutputStream ("myfile.txt");
String myName = ("Hello World!!!\nLine 2\nLine 3");
// Print a line of text
new PrintStream(fout).println (myName);
// Close our output stream
fout.close();
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("myfile.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 if any
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
}
}
so if i wanted it to just look and see if the file said "Line 3"?
I don't wish to show my code, but here's basically the output input method i'm using
import java.io.*;
public class OutputInput
{
// Main method
public static void main (String args[])
{
try
{
// Open an output stream
FileOutputStream fout = new FileOutputStream ("myfile.txt");
String myName = ("Hello World!!!\nLine 2\nLine 3");
// Print a line of text
new PrintStream(fout).println (myName);
// Close our output stream
fout.close();
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("myfile.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 if any
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
}
}
so if i wanted it to just look and see if the file said "Line 3"?