Java Reference
In-Depth Information
File: its/TextIO/LineRead.java
package its.TextIO;
1.
2.
3.
import java.io.*;
4.
5.
public class LineRead
6.
{
7.
// This variable has to be set according to your system
8.
public static String path = "./its/TestData/";
9.
public LineRead(String ReadFileName)
10.
{
11.
File readfile = new File(path+ReadFileName);
12.
String line;
13.
try
14.
{
15.
BufferedReader bfr = new BufferedReader( new FileReader(readfile));
16.
while ((line = bfr.readLine()) != null )
17.
{
18.
System.out.println("READ>"+line+"<");
}
19.
}
20.
catch (Exception ex)
21.
{
22.
System.out.println("Problem opening file "+readfile.getName());
23.
}
24.
}
25.
26.
27.
public static void main(String[] args)
28.
{
29.
LineRead LR = new LineRead("testtext1.txt");
30.
}
31.
}
10.2
Displaying text
We now show how to display text in a graphical component and not just on the
console. We use a JEditorPane to do this. We could have used other components
as well ( JTextArea or JTextPane ) but this one seems best suited for our purpose.
JEditorPane()
void read(Reader myReader, Object description)
String getText()
Search WWH ::




Custom Search