Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: FileReader help

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default FileReader help

    I gotta be honest, it's getting very hard for me to understand the lectures of my professor. I ask questions but I rarely get the answer I'm looking for. This time, he gave us an assignment about FileReaders telling us to search the internet for answers... I've been at this for the past 3 hours and I still couldn't get the answers right.. Please help me.. And please explain my errors so I at least get up to speed with our lectures...

    import java.io.*;
     
    class HomeWork4
    {
            public static void main (String[] args) throws Exception
            {
                    BufferedReader brfile = new BufferedReader (new FileReader("Love the Way You Lie.txt"));
                    FileInputStream fis = new FileInputStream("Love the Way You Lie.txt");
                    BufferedReader brfis = new BufferedReader(new InputStreamReader(fis));
     
                    File file = new File ("Love the Way You Lie.txt");
     
                    System.out.println("1. ToUpperCase"); //Print the lyrics in uppercase. Does this work? XD
                    System.out.println(file.toUpperCase());
     
                    System.out.println("2. The file size is: "+file.length());//get the file size in bytes.
     
                    System.out.println("3. Getting the second word of the file: ");//get the second word of the file only. I can't seem to get this right.. :(
                    String strLine = null, tmp;
                    while ((tmp = brfis.readLine()) != null)
                      {
                         strLine = tmp;
                      }
                      String lastLine = strLine;
                      System.out.println(lastLine);
     
                    System.out.println("4. Reverse the text file: ");//Print the lyrics in inverse order. I can't seem to get this working either
                    final StringBuilder stringBuilder = new StringBuilder(file);
                    System.out.println(stringBuilder.reverse());
     
            }
    }

    Any and all help would be appreciated... And any and all explanations would be appreciated more.. XD

    Also, my home computer is under repair so I really haven't compiled this with a program. Only with a somewhat unreliable online compiler...

    Thanks a lot!
    Last edited by bibboorton; September 2nd, 2010 at 08:18 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,130
    Thanks
    52
    Thanked 2,286 Times in 2,257 Posts

    Default Re: FileReader help

    please explain my errors
    Can you give us your errors or question?
    Please copy and paste here the full text of the error messages.

  3. #3
    Junior Member
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: FileReader help

    Here's my errors..

    line 14 - cannot find symbol method toUpperCase()
    line 28 - cannot find symbol method Stringbuilder(java.io.*)

    And a question as to how FileReader basically works.. I have no idea how it works.. And the examples I find on the internet are quite confusing.. :/

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,130
    Thanks
    52
    Thanked 2,286 Times in 2,257 Posts

    Default Re: FileReader help

    Please copy and paste here the full text of the error messages.
    The full text of the message has useful info. Your edited version leaves stuff out.

    What don't you understand about: cannot find?

    Does the File class have a method by that name?
    Is there a constructor for the StringBuilder class that takes a File as argument?

  5. #5
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: FileReader help

    BufferedReader brfile = new BufferedReader (new FileReader("Love the Way You Lie.txt"));
    FileInputStream fis = new FileInputStream("Love the Way You Lie.txt");
    BufferedReader brfis = new BufferedReader(new InputStreamReader(fis));

    File file = new File ("Love the Way You Lie.txt");
    Why so many if you can finish your assignment with only one bufferedReader? Here is a website that has a tutorial for everything you need. BufferedReader << File << Java Tutorial
    Last edited by Brt93yoda; September 4th, 2010 at 11:38 PM.

  6. #6
    Junior Member
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: FileReader help

     
    Main.java:14: cannot find symbol
    symbol  : method toUpperCase()
    location: class java.io.File
                    System.out.println(file.toUpperCase());
                                           ^
    Main.java:28: cannot find symbol
    symbol  : constructor StringBuilder(java.io.File)
    location: class java.lang.StringBuilder
                    final StringBuilder stringBuilder = new StringBuilder(file);
                                                        ^

    Sorry..

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,130
    Thanks
    52
    Thanked 2,286 Times in 2,257 Posts

    Default Re: FileReader help

    file.toUpperCase()
    Does the File class have a method with that name? The compiler doesn't think it does.

    new StringBuilder(file)
    Does the StringBuilder class have a constructor that takes a File class object as an arg? The compiler can't find it.

    What are you trying to do in these two statements? Try reading the API doc for each of those classes to see how to use them.
    Java Platform SE 6

Similar Threads

  1. [SOLVED] FileReader.read() reads garbage
    By Hackworth in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: August 27th, 2010, 01:06 PM
  2. [SOLVED] difference between fileReader and bufferReader
    By shadihrr in forum Java Theory & Questions
    Replies: 6
    Last Post: June 8th, 2010, 01:26 AM
  3. FileReader need assistance
    By tazjaime in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: November 8th, 2009, 12:12 AM

Tags for this Thread