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 2 of 2

Thread: quite small (make the changelog non-static, i.e. load its content from a file)

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default quite small (make the changelog non-static, i.e. load its content from a file)

    To the Java developers,
    I am currently having trouble with change the Changelogfrom hardcoded to a readout from a text file called "Changelog.txt".
    So far i have made a class called ReadWriteChangelog.java
    and here is the code i placed in: -
    package org.freelords.forms.newgame;
     
    import java.io.*;
    import java.util.*;
     
    import org.freelords.forms.newgame.ChangelogForm;
     
    public class ReadWriteChangelog {
     
     
    public static String getFileContents(String filename) throws IOException {
     
    char[] buf = new char[512];
    int len = 0;
    StringBuilder builder = new StringBuilder();
    FileReader reader = new FileReader(filename);
    while (((len = reader.read(buf, 0, buf.length)) != -1))
    {
    builder.append(buf, 0, len);
    }
    String text = builder.toString();
    BufferedReader buffReader = new BufferedReader(reader);
    while (((len = buffReader.read(buf, 0, buf.length)) != -1))
    {
    builder.append(buf, 0, len);
    }
     
    char[] buffer = new char[512];
    try 
    {
    while (((len = buffReader.read(buf, 0, buf.length)) != -1))
    {
    builder.append(buf, 0, len);
    }
    }
    finally
    {
    buffReader.close();
    }
    return builder.toString();
    }
    }
     
    And what i did on the class ChangelogForm.java i tried to make the class read from the ReadWriteChangelog.java and that is what i written : -
     
     
     
    public void init(Composite parent) {
    super.init(parent);
    File file = new File("I:\\eclipseproject\\eclipseFreelordsUI\\src\ \org\\freelords\\forms\\newgame\\Changelog.txt");
     
    try {
    //".\\FreelordsUI\\src\\org\\freelords\\forms\\newga me\\Changelog.txt"
    Changelog = ReadWriteChangelog.getFileContents();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    description.setText(Changelog);
     
    }
    I am able to operate the Open source game but the code reading the text file can't pass the file contents over to the button to display.If you find a solution to this please reply to this thread or let me know by email.Thank you.
    Last edited by helloworld922; November 28th, 2009 at 10:30 AM.


  2. #2
    Member Truffy's Avatar
    Join Date
    May 2009
    Location
    Philippines
    Posts
    93
    Thanks
    2
    Thanked 9 Times in 7 Posts

    Default Re: quite small (make the changelog non-static, i.e. load its content from a file)

    Quote Originally Posted by Abdallah View Post
    To the Java developers,
    I am currently having trouble with change the Changelogfrom hardcoded to a readout from a text file called "Changelog.txt".
    So far i have made a class called ReadWriteChangelog.java
    and here is the code i placed in: -
    package org.freelords.forms.newgame;
     
    import java.io.*;
    import java.util.*;
     
    import org.freelords.forms.newgame.ChangelogForm;
     
    public class ReadWriteChangelog {
     
     
    public static String getFileContents(String filename) throws IOException {
     
    char[] buf = new char[512];
    int len = 0;
    StringBuilder builder = new StringBuilder();
    FileReader reader = new FileReader(filename);
    while (((len = reader.read(buf, 0, buf.length)) != -1))
    {
    builder.append(buf, 0, len);
    }
    String text = builder.toString();
    BufferedReader buffReader = new BufferedReader(reader);
    while (((len = buffReader.read(buf, 0, buf.length)) != -1))
    {
    builder.append(buf, 0, len);
    }
     
    char[] buffer = new char[512];
    try 
    {
    while (((len = buffReader.read(buf, 0, buf.length)) != -1))
    {
    builder.append(buf, 0, len);
    }
    }
    finally
    {
    buffReader.close();
    }
    return builder.toString();
    }
    }
     
    And what i did on the class ChangelogForm.java i tried to make the class read from the ReadWriteChangelog.java and that is what i written : -
     
     
     
    public void init(Composite parent) {
    super.init(parent);
    File file = new File("I:\\eclipseproject\\eclipseFreelordsUI\\src\ \org\\freelords\\forms\\newgame\\Changelog.txt");
     
    try {
    //".\\FreelordsUI\\src\\org\\freelords\\forms\\newga me\\Changelog.txt"
    Changelog = ReadWriteChangelog.getFileContents();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    description.setText(Changelog);
     
    }
    I am able to operate the Open source game but the code reading the text file can't pass the file contents over to the button to display.If you find a solution to this please reply to this thread or let me know by email.Thank you.
    Hi Abdallah,

    Welcome to the forum.

    You are using GUI? or this program is only run if you press a button? AM i right?

    Cheers.
    Truffy.

Similar Threads

  1. Static method
    By kalees in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 20th, 2009, 11:10 AM
  2. Arraylist Save and Load
    By frankycool in forum Collections and Generics
    Replies: 1
    Last Post: November 14th, 2009, 06:48 AM
  3. Small Project Ideas
    By Freaky Chris in forum Project Collaboration
    Replies: 20
    Last Post: August 12th, 2009, 12:49 PM
  4. Content positioning on the screen
    By Drakenmul in forum AWT / Java Swing
    Replies: 1
    Last Post: July 27th, 2009, 09:02 AM
  5. Java program for downloading contents from the web
    By alley in forum Java Networking
    Replies: 8
    Last Post: June 17th, 2009, 01:13 PM