java - Reading input from a file in a specific pattern -


i have text file have read array list. looks this:

[up, 1, up, 1, up, 1, left, 1, right, 1, down, 3]

how separate inputs arraylist in way assign numbers following method up(int n) until next method left(int n) , on?

lol threw check , see if works.

bufferedreader br = new bufferedreader(new filereader("myfile.txt")); string line = br.readline(); string [ ] words = line.split ( "," ); for(int = 0; < words.length; i++) {     switch(words[i])     {        case " up":        case "up":            moveup(integer.parse(words[i + 1]);            i++;            break;         case " down":        case "down":            movedown(integer.parse(words[i + 1]);            i++;            break;         case " left":        case "left":            moveleft(integer.parse(words[i + 1]);            i++;            break;         case " right":        case "right":            moveright(integer.parse(words[i + 1]);            i++;            break;     } } 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -