String dexVersion返回null
我尝试了很多东西,比如取一个字符串并附加一个readData [] char并且它工作正常,我也试着看看它是否是字符而不是字符,但结果是不确定的
import java.io.*;
import java.net.*;
import java.lang.*;
import java.util.*;
class main {
public static void main(String args[]) {
String version = new String("1.0 (Alpha)");
main main = new main();
dataHandling data = new dataHandling();
boolean doneProcessing = false;
int x = 0,y = 0;
String dexVersion = new String("v:");
String pokemon[][] = new String[700][10];
System.out.println(":");
System.out.println("POKeUTILITY:MAIN_THREAD_STARTED_IN_STATIC_METHOD_MAIN");
System.out.println("POKeUTILITY:STARTING_VERSION=" + version);
System.out.println("POKeUTILITY:DOWNLOADING_POKeDEX_DATA");
data.download();
System.out.println("POKeUTILITY:READING_POKeDEX_DATA");
char readData[] = data.read();
System.out.println("POKeUTILITY:PROCESSING_POKeDEX_DATA");
while (doneProcessing = false) {
if ((readData[x]) == '{') {
x++;
while ((readData[x]) != '}') {
dexVersion += readData[x];
x++;
}
}
// if ((readData[x]) == '[') {
// x++;
// while ((readData[x]) != ']') {
// dexVersion += readData[x];
// x++;
// }
// }
if ((readData[x]) == '%') doneProcessing = true;
x++;
}
System.out.println(dexVersion + ".");
}
}
class dataHandling {
public void download() {
BufferedInputStream dFile;
FileOutputStream wFile;
try {
dFile = new BufferedInputStream(new URL("http://www.harry.technology/pokedex").openStream());
wFile = new FileOutputStream("pokedex");
int x = 0,y = 0;
while ((x = dFile.read()) != -1) {
wFile.write(x);
}
wFile.close();
dFile.close();
} catch (IOException e) {
System.out.println("POKeUTILITY:ERROR_" + e);
System.exit(0);
}
}
public char[] read() {
int x = 0,y = 0;
char input[] = new char[2000];
String output = new String("");
try {
FileReader file = new FileReader("pokedex");
while ((x = file.read()) != -1) {
input[y] = convert(x);
y++;
}
file.close();
} catch (IOException e) {
System.out.println("POKeUTILITY:ERROR_" + e);
System.exit(0);
}
return input;
}
public char convert(int a) {
switch (a) {
ASCII SWITCH STATEMENT (left out because of length)
}
}
}
这是文件" pokedex":
{1.0}
[001,Bulbasaur]
%
在我的服务器上查看