Originally Posted by
Abdallah
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.