over 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!"); }
}
}
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[1]:Bangladesh
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
Can you help out the community by solving one of the following Javascript problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Answer(s)