import java.io.*;
import java.util.*;

public class array {
    public static void main(String[] args) throws IOException {
        FileInputStream in = null;
        FileOutputStream out = null;
       
try {
    in = new FileInputStream("input.txt");
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    String line = null;
    while ((line = reader.readLine()) != null) {
       String split[]=line.split(",");
      
    }


}
   
 catch (IOException x) {
    System.err.println(x);
} finally {
    if (in != null) in.close();
}}}

I'm stuck at how to convert string in split into int. My input.txt :

a,b,c
2,2,1
1,1,1
2,2,1
3,3,1
4,4,1
5,5,1
1,6,2
2,7,2
3,8,2
4,9,2
5,10,2

Anyone can help?

Recommended Answers

All 3 Replies

Use string.split(","); then use a for loop to iterate over the array it returns. Use the Integer.parseInt(string) method to convert each String in the array into an int.

Use string.split(","); then use a for loop to iterate over the array it returns. Use the Integer.parseInt(string) method to convert each String in the array into an int.

can you show me the code? please...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.