Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[help] inputfile java please click me to know more
14-04-2013, 10:02 PM,
Post: #1
[help] inputfile java please click me to know more
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
[Image: Captu3re.jpg]
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Soalan Java darknite 10 793 27-11-2013, 01:47 PM
Last Post: darknite
  soalan java. hard3 4 902 10-05-2013, 10:33 PM
Last Post: JejakaPemalu
  [problem]with java tcp client and server chat pron3t 1 548 26-02-2013, 01:21 PM
Last Post: muhaznar
  java API Timon 3 814 09-12-2012, 09:58 PM
Last Post: lamki
  java background music library Timon 0 439 09-12-2012, 05:21 PM
Last Post: Timon
  JAVA Layout... mana 1 feveret :P 127001 7 1,663 03-12-2012, 10:32 AM
Last Post: Wushipher
  Java | MS Excell 127001 5 1,031 29-07-2012, 12:41 AM
Last Post: lamki
  Tutorial: Menghubungkan SQLite Dengan Java s3m00t 4 1,275 25-07-2012, 02:40 AM
Last Post: s3m00t
  [java prob]guna user input dan methode erroe indintifier pron3t 2 655 22-04-2012, 07:56 PM
Last Post: pron3t
  [Tut]Java Array Name Ujang 2 722 19-04-2012, 03:07 PM
Last Post: pron3t

Forum Jump: