TBD.my

Full Version: [help] inputfile java please click me to know more
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
bagaimana hendak extra numbor sebagai variable int sahaja dalam file .txt ini tersebut

Quote:0: 13 19
1:
2: 6 11 19
3:
4: 13
5: 7 9
6: 2 7
7: 5 6 16
8: 12
9: 5
10:
11: 2
12: 8 18
13: 0 4
14: 15
15: 14 15
16: 7 19
17:
18: 12
19: 0 2 16

saya sudah try eliminate samada spacing dia atau titik bentindih sahaja tetapi untuk eliminate spacing sekali dengan titik bertindih tidak berjaya kerana for loop saya di dalam clause { } jadi tidak bole di kerluarkan untuk membuat proses eliminate seterusnya tersebut

Code:
import java.io.*;

public class inputfile {
    public static void main(String[] args) {
        File file = new File("graph.txt");
        StringBuilder contents = new StringBuilder();
        BufferedReader reader = null;

        try {
            reader = new BufferedReader(new FileReader(file));
            String text = null;

            // repeat until all lines is read
            while ((text = reader.readLine()) != null) {
                contents.append(text).append(System.getProperty("line.separator"));
            
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        // show file contents here
        String str = contents.toString();

      
        String[]result = str.split(":");
        for (int x=0; x<result.length; x++) {
        
      
                System.out.println(result[x]);
            
         }

coding berikut akan memisahkan numbor dengan titik bertindih ssahaja anda mesti tolong saya pls