• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stringbuffer class?  RSS feed

 
Kalona Ark
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  • I am having trouble with the following: use the StringBuffer class to create an object

  • read the text text from the file named "input.txt" and storing the contents in the StringBuffer object
    [ December 09, 2007: Message edited by: Kalona Ark ]
    [ December 09, 2007: Message edited by: Kalona Ark ]
     
    Nicholas Jordan
    Ranch Hand
    Posts: 1282
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Looks hard for beginner, but is simple a matter of continuing to work and read.

    To make a StringBuffer object:

    StringBuffer buffy = new StringBuffer();// called default construction.

    To read text, I think you want another class in java.io

    The Scanner class is designed to do a bunch of work for you. Try

    BufferedReader in = new BufferedReader(new FileReader("foo.in"));

    See: http://java.sun.com/j2se/1.5.0/docs/api/java/io/BufferedReader.html and look for readLine();// returns a String
     
    Kalona Ark
    Greenhorn
    Posts: 20
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for the advice.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!