using FileReader instead of BufferedReader

Hi! i'm trying to write a code that can read a file without stopping when there's a line break. i've understood that i should use read() instead of readLine() but also that i should use FileReader instead of BufferedReader because "The major function of BufferedReader is to break the input into lines. " (copied from another thread here at sun).

Here's my problem, it doesn't work when i try to exchange BufferedReader for FileReader, anyone knows how to do it?

publicclass LearnLine{

public LearnLine(){}

publicstaticvoid main (String[] args){

String REGEX ="file with";

String INPUT;

try{

FileInputStream fstream =new FileInputStream("Test.txt");

// Get the object of DataInputStream

DataInputStream in =new DataInputStream(fstream);

BufferedReader br =new BufferedReader(new InputStreamReader(in));

while ((INPUT = br.readLine()) !=null){

Pattern p = Pattern.compile(REGEX);

Matcher m = p.matcher(INPUT);

while (m.find()){

System.out.println("found it");

}

}

}catch (Exception e){

System.out.println("heyheyhey");

e.printStackTrace();

}

}

}

[2206 byte] By [SandraPandraa] at [2007-11-27 5:42:30]
# 1
I'm a bit lost as to what you are trying to do because FileReader does not support the reading of lines.
sabre150a at 2007-7-12 15:21:14 > top of Java-index,Java Essentials,Java Programming...
# 2
Yes, step away from the code and tell us what the specification is.
Hippolytea at 2007-7-12 15:21:14 > top of Java-index,Java Essentials,Java Programming...
# 3

>I'm a bit lost as to what you are trying to do because FileReader does not support the reading of lines.

> Yes, step away from the code and tell us what the

> specification is.

what i would like to do, when it's finished, is to search for a given string without breaking at line break, pagebreak or comma, but to break when there's a colon, period or quotationmark... i would like to be able to specify exactly what it should count as a "word character" and where to break and as i've understood it "read()" is the best function for this. then i found out that FileReader is better to use for this than BufferedReader so that's what i'm trying to get my mind around.

SandraPandraa at 2007-7-12 15:21:14 > top of Java-index,Java Essentials,Java Programming...
# 4
Now you tell us! How big is the file? You could read it all into a StringBuilder,then take the resulting String and split() it.
Hippolytea at 2007-7-12 15:21:14 > top of Java-index,Java Essentials,Java Programming...
# 5
it's a pretty big file, around eight thousand pages pure text.
SandraPandraa at 2007-7-12 15:21:14 > top of Java-index,Java Essentials,Java Programming...
# 6
> it's a pretty big file, around eight thousand pages pure text.I can see why you wouldn't want to read all that into memory!Have you tried java.util.Scanner? It can be configured with a givendelimiter pattern.
Hippolytea at 2007-7-12 15:21:14 > top of Java-index,Java Essentials,Java Programming...
# 7
> I can see why you wouldn't want to read all that into> memory!> Have you tried java.util.Scanner? It can be> configured with a given> delimiter pattern.no it's new to me, but i'll go check it immediately
SandraPandraa at 2007-7-12 15:21:14 > top of Java-index,Java Essentials,Java Programming...
# 8

Here is a quick demo.

import java.util.*;

import java.util.regex.*;

public class ScannerExample {

public static void main(String[] args) {

Pattern delimiter = Pattern.compile("[:.]");

Scanner scanner = new Scanner("This is an example: a colon. That was fun. Done");

scanner.useDelimiter(delimiter);

while (scanner.hasNext()) {

System.out.format("[%s]%n", scanner.next());

}

}

}

You can pass other things to Scanner's constructors, like File objects, of course.

Hippolytea at 2007-7-12 15:21:14 > top of Java-index,Java Essentials,Java Programming...
# 9
great thanks Hippolyte!
SandraPandraa at 2007-7-12 15:21:14 > top of Java-index,Java Essentials,Java Programming...