Note that there are some explanatory texts on larger screens.

plurals
  1. POSpaces added in while reading from file...?
    primarykey
    data
    text
    <p>I'm trying to read a word and its corresponding code from a file for a project. This is the code I have, and it reads it fine, just for some reason spaces are added after some, but not all, of the codes. I do not understand why it is happening. </p> <p>The code is:</p> <pre><code>public void loadDictionary(String file){ String fileName=file; String fileNameTwo=file; //Coder c=new Coder(); String string; String code; String s=null; try{//System.out.println("1"); FileReader freader=new FileReader(fileName); FileReader freaderTwo=new FileReader(fileNameTwo); //System.out.println("1"); BufferedReader inFile=new BufferedReader(freader); BufferedReader inFileTwo=new BufferedReader(freaderTwo); //System.out.println("2"); //System.out.println("3"); if ((s=inFile.readLine())==null){ System.out.println("5"); throw new EmptyFileException("Nothing in file to upload."); } while ((s=inFileTwo.readLine())!=null){ //System.out.println("4"); //System.out.println(s); String[] tokens=s.split(" "); string=tokens[0]; //System.out.println(string); code=tokens[1]; //System.out.println(code); this.insert(string, code); System.out.println(code+"."); }//end while //this.printCoder(); }//end try catch(EmptyFileException ex){ } catch(IOException ex){ System.out.println("Error in uploading dictionary."); } }//end method </code></pre> <p>...and the output is (of the codes):</p> <pre><code> 5721. 9963. 4432 . 1143 . 6402 . 3333 . 4924 . 1429 . 3110 . 3036 . 2736 . 8064. </code></pre> <p>The periods are there to show how many spaces are added in. I just appended a period in the system.out.println().</p> <p>Edit: The periods aren't coming out quite right....but you get the idea. The are really sometimes more/less spaces than it is showing.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload