Results 1 to 1 of 1
  1. #1
    Abdallah1 is offline Member
    Join Date
    Nov 2009
    Posts
    1
    Rep Power
    0

    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 Abdallah1; 11-28-2009 at 05:04 PM.

Similar Threads

  1. make static ref to non-static method?
    By McChill in forum New To Java
    Replies: 7
    Last Post: 02-23-2009, 06:48 AM
  2. Usual problem: cannot make a static....
    By hendrix79 in forum New To Java
    Replies: 2
    Last Post: 12-15-2008, 04:19 PM
  3. Please help, need to make my class static.
    By sumak in forum New To Java
    Replies: 1
    Last Post: 04-19-2008, 08:29 AM
  4. How to load binary content of a .class file
    By boy22 in forum Advanced Java
    Replies: 1
    Last Post: 08-03-2007, 07:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •