I want to copy http://docs.oracle.com/javase/tutorial/collections/interfaces/examples/dictionary.txt into an array for hangman game. I have this so far..
url = new URL("http://docs.oracle.com/javase/tutor… );
urlConn = url.openConnection();
urlConn.getInputStream());
inStream in = new InputStreamReader("dictionary.txt");
urlConn.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String nextLine;
String[] secretwordbank;
secretwordbank = new String[80368];
secretwordbank is an array representing a dictionary of words. This may be too big of an array so I’m open for ideas to optimize it. Anyone know how to do it?
Are you really just unsure how to convert a
BufferedReaderinto an array (or other collection) of strings, based on line breaks? If so, I’d suggest using Guava:(As an aside, I would suggest specifying an encoding when creating the
InputStreamReader– otherwise it will use the platform default encoding. Ideally, you should use the content-type header from the response to determine the encoding… there are higher-level HTTP libraries which will do all of this for you, such as HttpClient.)