Which Java IO class is better to use for a simple shell interpreter? -
i new java io library, have trouble choosing right class purposes. write simple shell client file transferring server. client should understand 3 commands: list files in remote directory (optionally can take nested directory path argument), download specified file (with file path required argument) , end session (a separate command). concerned handling user's input @ moment. questions are:
- should read whole line of input, tokenize , logic, or better tokenize input comes , make immediate decisions based on it?
- what class should use tokenize input: scanner or streamtokenizer? or taking account commands simple use bufferedreader read line, split string
"\\s+"
pattern?
the questions may seem subjective in way want diminish confusion , understand specific use cases of io classes.
- considering commands basic, reading whole input , tokenizing require lot of efforts. better tokenize input , take decisions required.
i think bufferedreader sufficient serve purpose here. make code easy. when working on taking input csv file , tokenizing display graph used same. logic parsing string goes below:-
string splitby = ";"; // using csv file below used ";" splitter. can change per needs bufferedreader br = new bufferedreader(new filereader("file.csv")); string line = br.readline(); while((line = br.readline()) != null) { string[] b = line.split(splitby); //take actions need perform } br.close();
hope answers question. let me know if more details required.
Comments
Post a Comment