Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get integers from strings in my situation?
    primarykey
    data
    text
    <p><strong>Short story:</strong> I generate random numbers and end symbol 0-9/ ( '/' is line end symbol, if I meet it, I go to write to next line in file.) When I generated my numbers and put in file, I want to get back those numbers from file but in not like strings, it should be Integers.</p> <p>Assume my file looks like this:</p> <pre><code>846525451454341* * 0067617354809629733035* 3313449117867514* 02337436891267261671546* 469980603887044* 7* 9* 642* * 0617044835719095066* 5* 7175887168189821760* 581* 76300152922692817* </code></pre> <p>As you can noticed, line is able to hold only '*' in some cases (As I said it is generated random).</p> <h2><strong>My purpose</strong></h2> <p>I want to get back these lines like integers. For example I take 1 line until I meet end symbol ( '/' ) then I loop another line and so on.</p> <p>Some snippet:</p> <pre><code> public void readGeneratedFile() throws IOException { try(BufferedReader r= new BufferedReader(new FileReader("C:\\java\\numbers.txt"))){ int ch; s = new String(); while((ch=r.read())!=-1){ s+=String.valueOf(Character.toChars(ch)).replace(" ",""); // Here I take all file into String, But this approach is leading to boilerplate code; } // catch IOException , finally close the file. </code></pre> <h2><strong>My question</strong></h2> <p>How can I get back those lines like integers? (Suppose I want to take some actions with those numbers) It's cool if you get an idea what I want to do.</p> <p>Thanks.</p> <h2><strong>EDITED:</strong></h2> <p><strong>Sorry for misunderstanding, It is not what I want. I want to get back separated values, For example I have 123456/564654/21 string, and my Integer array[1][index] should looks like 1,2,3,4,5,6 then I meet end line symbol '/' I jump to array[2][index] and fill it with next line in file.</strong></p>
    singulars
    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.
 

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