Jump to content

BufferedReader

- - - - -

  • Please log in to reply
30 replies to this topic

#1
PicklishDoorknob

PicklishDoorknob

    Learning Programmer

  • Members
  • PipPipPip
  • 86 posts
Very short beginning here.
import java.io.*;


public class FileReader {

	BufferedReader reader = new BufferedReader(new Reader());

}

It doesn't work giving a compiler error: Cannot instantiate the type Reader. :confused::confused::confused:

EDIT: Same with this:
import java.io.*;


public class FileWriter {

	BufferedWriter writer = new BufferedWriter(new Writer());

}

Cannot instantiate the type Writer.

#2
Animus

Animus

    Newbie

  • Members
  • PipPip
  • 26 posts
just what exactly are you trying to make here?

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Reader and Writer are abstract classes, you need to create a concrete class which extend those.
For Reader:
BufferedReader, CharArrayReader, FilterReader, InputStreamReader, PipedReader, StringReader
For Writer:
BufferedWriter, CharArrayWriter, FilterWriter, OutputStreamWriter, PipedWriter, PrintWriter, StringWriter

#4
PicklishDoorknob

PicklishDoorknob

    Learning Programmer

  • Members
  • PipPipPip
  • 86 posts
So I've done this:
import java.io.*;


public abstract class FileWriter extends Writer{

	FileWriter() {

		BufferedWriter writer = new BufferedWriter(this);

	}

}

But now I can't use the constructor because the class is abstract! I don't want to change the methods so I can't override them. help?
Main class:
public class Begin {


	/**

	 * @param args

	 */

	public static void main(String[] args) {

		new GUI(); new FileReader(); new FileWriter();

	}


}


EDIT:
OK so I overrode[?] them and now I need to know how to delete characters (other than reading the whole file, deleting it, and making a new file without the character(s).

EDIT: AHH
I can't access writer and reader from my main class! (the ones created in the constructor!

OH WAIT never mind couldn't I just make somepublic methods in my other classes? Wait a minute I'm confused. :confused:

#5
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
I have no idea, what you are trying to do, but here's an example how to instantiate one.

File file = new File("alphabet_soup.txt");
BufferedReader in = new BufferedReader(new FileReader(file));

.

#6
PicklishDoorknob

PicklishDoorknob

    Learning Programmer

  • Members
  • PipPipPip
  • 86 posts

Sinipull said:

I have no idea, what you are trying to do, but here's an example how to instantiate one.


File file = new File("alphabet_soup.txt");

BufferedReader in = new BufferedReader(new FileReader(file));

I did that an it gave an error. Time to update Java?

#7
Norm

Norm

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 327 posts

Quote

it gave an error.
When you get errors that you want help with, copy and paste them on the forum.

#8
PicklishDoorknob

PicklishDoorknob

    Learning Programmer

  • Members
  • PipPipPip
  • 86 posts
Attached File  error.png   9.06K   11 downloads

#9
Norm

Norm

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 327 posts
Can you post something that is readable?

To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

#10
PicklishDoorknob

PicklishDoorknob

    Learning Programmer

  • Members
  • PipPipPip
  • 86 posts
It's an image. Click it.

Anyway, the code:
import java.io.*;


public class FileReader {

	File file = new File("data.txt");

	BufferedReader in = new BufferedReader(new FileReader(file));

}
The errors:
The constructor BufferedReader(FileReader) is undefined.
Theconstructor FileReader(File) is undefined.

#11
Norm

Norm

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 327 posts
Thanks.

Compiles with no errors for me with jdk1.6.

What versions of software are you using to do your compiles?

#12
PicklishDoorknob

PicklishDoorknob

    Learning Programmer

  • Members
  • PipPipPip
  • 86 posts

Norm said:

Thanks.

Very helpful?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users