CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2009
    Posts
    0

    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 can be able to operate the menu of the open source game but i can operate the Game very well but i can make the Changelog button to read from the "Changelog.txt". If you find a solution to this please reply to this thread or let me know by email.Thank you.

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

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

    I don't see how that code compiles - the getFileContents method takes a String parameter, but you're trying to call it without any parameters.

    If you're going to post code that runs, post the code that runs, otherwise it just wastes everyone's time.

    You'll find a nicer way to read a text file in the Java Tutorials.

    Bad code isn't bad, its just misunderstood...
    Anon.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured