The purpose of this application is to query CSV files.
Running example
java QueryCSV dns.csv 0 1baidu.com123.125.114.144zjgsu.edu.cn202.96.99.58
Code
The Java standard library of Princeton University is used in the Code. Please click here to download: http://introcs.cs.princeton.edu/java/stdlib/
Import java. util. hashMap; import java. util. linkedHashMap; public class QueryCSV {public static void main (String [] argv) {In in = new In (argv [0]); int keyField = Integer. parseInt (argv [1]); int valueField = Integer. parseInt (argv [2]); // create a hash table HashST
Map = new HashST
(); While (! In. isEmpty () {String line = in. readLine (); String [] s = line. split (","); map. put (s [keyField], s [valueField]);} // process the query operation while (! StdIn. isEmpty () {String key = StdIn. readString (); String value = map. get (key); if (value = null) StdOut. println ("Not Found"); else StdOut. println (value );}}}
Dns.csv File Content
baidu.com,123.125.114.144zjgsu.edu.cn,202.96.99.58abc.com,199.181.132.250