about 5 years ago
I want split string from file into two array string......
file contain this-
public class Reversewhileloop { /** * @param args the command line arguments * @throws java.io.FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException, IOException { try { BufferedReader in = new BufferedReader(new FileReader(new File("Untitled Document 1.txt"))); System.out.println("File open successful!"); int line = 0; String[] tempArray; for (String x = in.readLine(); x != null; x = in.readLine()) { line++; String[] tokens = x.split("="); for (int i = 0; i < tokens.length; i++) { System.out.println("Str[" + i + "]:" + tokens[i]); } } } catch (IOException e) { System.out.println("File I/O error!"); } } }
Output is-
Str[0]:Bangladesh
Str[1]: 109.408
Str[0]:India
Str[1]: 92.7478
Str[0]:Pakistan
Str[1]: 200.550
Str[0]:USA
Str[1]: 1.29221
but I want output like this way-
Str[1]:Bangladesh
Str[2]: 109.408
Str[3]:India
Str[4]: 92.7478
Str[5]:Pakistan
Str[6]: 200.550
Str[7]:USA
Str[8]: 1.29221
OR
Str[2]:India
Str[3]:Pakistan
Str[4]:USA
Str1[1]:109.408
Str1[2]: 92.7478
Str1[3]: 200.550
Str1[4]: 1.29221
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Sign up using
0 Answer(s)