Abdallah1
November 28th, 2009, 03:46 AM
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. :)
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. :)