我正在尝试从文件中读取数据并将数据存储在三个整数中,红色、绿色和蓝色文件中的数据设置为:
255,0,0
0,255,0
0,0,255
0,255, 255
我已经尝试过这样做的方法,但我没有成功任何人都可以帮助这里是迄今为止该方法的副本:
private void readColoursFromFile() {
int red = 128;
int green = 128;
int blue = 128;
StringBuilder contents = new StringBuilder();
String filename = "colours.txt";
try {
BufferedReader reader;
reader = new BufferedReader(new FileReader(filename));
String str;
while (( str = reader.readLine()) != null) {
StringTokenizer tokenizer = new StringTokenizer(str, ",");
String rcolour = tokenizer.nextToken();
String gcolour = tokenizer.nextToken();
String bcolour = tokenizer.nextToken();
Integer irColour = red;
Integer igColour = green;
Integer ibColour = blue;
rcolour = Integer.toString(irColour);
gcolour = Integer.toString(ibColour);
bcolour = Integer.toString(igColour);
contents.append(str);
printColourRow(red, green, blue);
}
{
reader.close();
}
} catch (IOException e) {
System.out.println("error");
e.printStackTrace();
}
}