Java Scanner delimiter on values of nextLine
<p>I have a file in .dat format. Here is a sample</p>
<blockquote>
<p>||= (N              ) =||    1||  0.938  ||   ---    ||   0.5  ||  (****)||     0.5   ||      0   ||     0    ||     0    ||  0.700  ||  (p)=2212, (n)=2112  ||</p>
<p>||= (\Delta         ) =||    2||  1.232  ||   0.118  ||   1.5  ||  (****)||     1.5   ||      0   ||     0    ||     3    ||  1.076  ||  (\Delta^{++})=2224, (\Delta^+)=2214, (\Delta^0)=2114, (\Delta^-)=1114  ||</p>
<p>||= (P_{11}(1440)   ) =||    3||  1.462  ||   0.391  ||   0.5  ||  (****)||     0.5   ||      0   ||     0    ||     3    ||  1.076  ||  202212, 202112  ||</p>
<p>||= (S_{11}(1535)   ) =||    4||  1.534  ||   0.151  ||   0.5  ||  ( ***)||     0.5   ||      0   ||     0    ||     3    ||  1.076  ||  102212, 102112  ||</p>
</blockquote>
<p>I am trying to use Scanner to read this file and delimit the line by the &quot;||&quot; and then send into and ArrayList for future processing. Here is a sample of my code where I use the delimiter</p>
<pre><code>String file = &quot;data.dat&quot;;
Scanner s = null;
try {
    s = new Scanner(new File(file)).useDelimiter(&quot;\\|\\|&quot;); //here is the use of my delimiter

    ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
    while (s.hasNextLine()) {   //notice I am using hasNextLine because each line must be unique to create the HashMap 
        list.add(s.nextLine());
    }
    s.close();
    for (String string : list) {  //Lets print out the values of the list
        System.out.println(string);
    }
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} 
</code></pre>
<p>But my output still has values of the delimiter, i.e. here is the output:</p>
<blockquote>
<p>||= (N              ) =||    1||  0.938  ||   ---    ||   0.5  ||  (****)||     0.5   ||      0   ||     0    ||     0    ||  0.700  ||  (p)=2212, (n)=2112  ||</p>
<p>||= (\Delta         ) =||    2||  1.232  ||   0.118  ||   1.5  ||  (****)||     1.5   ||      0   ||     0    ||     3    ||  1.076  ||  (\Delta^{++})=2224, (\Delta^+)=2214, (\Delta^0)=2114, (\Delta^-)=1114  ||</p>
<p>||= (P_{11}(1440)   ) =||    3||  1.462  ||   0.391  ||   0.5  ||  (****)||     0.5   ||      0   ||     0    ||     3    ||  1.076  ||  202212, 202112  ||</p>
<p>||= (S_{11}(1535)   ) =||    4||  1.534  ||   0.151  ||   0.5  ||  ( ***)||     0.5   ||      0   ||     0    ||     3    ||  1.076  ||  102212, 102112  ||</p>
</blockquote>
<p>I have searched and found no answer that helped. I am also seeing a warning about a &quot;Resource leak: '' is never closed&quot; with the line</p>
<pre><code>s = new Scanner(new File(file)).useDelimiter(&quot;\\|\\|&quot;);
</code></pre>
<p>which disappears if the line is broken into</p>
<pre><code>s = new Scanner(new File(file));
s.useDelimiter(&quot;\\|\\|&quot;);
</code></pre>
<p>Any help is appreciated.</p>