0% found this document useful (0 votes)
36 views1 page

Read All Texte in Textbox

The document describes two methods for reading text from a file in Java. The first method uses a FileReader and BufferedReader to read each line of a text file and set it to the text of a JTextBox. The second method uses a FileInputStream, DataInputStream, and BufferedReader to read each line of a text file and print it to the console. Both catch potential IOExceptions.

Uploaded by

Mohamed Roua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views1 page

Read All Texte in Textbox

The document describes two methods for reading text from a file in Java. The first method uses a FileReader and BufferedReader to read each line of a text file and set it to the text of a JTextBox. The second method uses a FileInputStream, DataInputStream, and BufferedReader to read each line of a text file and print it to the console. Both catch potential IOExceptions.

Uploaded by

Mohamed Roua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

Read all Texte in TextBox



import java.io.*;
class Test1 {
public static void main (String [] arg){
JTextBox botext = new JTextBox() ;
File f = new File("Test.txt");
try {
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String c ;
while((c =br.readLine())!=null){
botext.setTexte (c);
}
br.close();
}
catch(IOException i){
System.out.print("Error");
}
}
}
2. 2
eme
Methode
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("textfile.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());
}
}
}
[email protected]

You might also like