学习了Java读文件按行读取,标记下
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import
java.io.IOException;
public class TestJava {
private static String[] open={"05","07","09","21","23","24","06"};
public static void main(String[] args) {
String path = "E:\\fangaiwen\\colordouble.txt";
try {
readFile(path);
} catch (
IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Java读取文件按行读取
* @param fileName 文件路径
* @throws IOException
*/
public static void readFile(String fileName) throws IOException {
File f = new File(fileName);
FileReader file = new FileReader(f);
BufferedReader br = new BufferedReader(file);
while (br.ready()) {
String[] array = br.readLine().toString().split(","); //把读取的一行转为数组
getColor(array);
}
br.close();
file.close();
}
static void getColor(String[] buyRet){
int redCount = 0;
int blueCount = 0;
for (int i = 0; i < buyRet.length-1; i++) {
String str = buyRet[i];
for (int j = 0; j < open.length-1; j++) {
String openStr = open[j];
if(str.equals(openStr)){
redCount++;
continue;
}
}
//当循环结束时查看哪些相等
if(i==buyRet.length-2){
blueCount = buyRet[6].equals(open[6]) ? 1:blueCount;
if(redCount>0 || redCount>3){
System.out.print("red="+redCount +" blue="+blueCount);
for (int k = 0; k < buyRet.length; k++) {
System.out.print(" "+buyRet[k]+",");
}
System.out.println();
}
}
}
}
}
------解决方案--------------------结贴给分吧
------解决方案--------------------恭喜楼主,本来是来接分的,混了那么久分数那么低。。。
------解决方案-------------------- 没看懂。直接给分吗
------解决方案--------------------哈哈 领分来了
------解决方案--------------------
------解决方案--------------------结贴给分吧
------解决方案--------------------jf 来了
------解决方案--------------------LZ这是神马意思?想表达啥意思?
------解决方案--------------------接分!!!!!
------解决方案--------------------祝你好运,给我分吧?
------解决方案--------------------
------解决方案--------------------够雷,接分
------解决方案--------------------接分= =
------解决方案--------------------接分0-0
------解决方案--------------------hahha niu