Badguy13
20th November 2011, 12:30 AM
gini gan...
ane punya kodingan kyk gini..
Spoiler for Baca.Java:
Quote:
package JISMC;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Baca {
static char spasi;
public static void main(String[] args) {
File file = new File("d:/test.txt");
StringBuffer contents = new StringBuffer();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String text = null;
// ulangi sampai semua baris terbaca
while ((text = reader.readLine()) != null) {
contents.append(text).append(System.getProperty("l ine.separator"));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
// tampilkan isi file
System.out.println(contents.toString());
}
}
nah diatas kan ada file test.txt
filenya isinya ginian
Spoiler for test.txt:
Quote:
1 0.002188 0.000000 0.000000 0.620521
2 0.002917 0.315417 0.188854 0.004440
3 0.000313 0.009825 0.008978 0.663125
4 0.111667 0.123855 0.078230 0.663125
ane punya array[i][j]
dengan i = indeks data 1,2,3,4
dan j = indeks data 0.00 dst
pertanyaannya....gmn ya supaya angka di test.txt bs masuk ke var array...
tolong bgt ya agan2...
penting bgt sebabnya ini...
thx before..
</div>
ane punya kodingan kyk gini..
Spoiler for Baca.Java:
Quote:
package JISMC;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Baca {
static char spasi;
public static void main(String[] args) {
File file = new File("d:/test.txt");
StringBuffer contents = new StringBuffer();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String text = null;
// ulangi sampai semua baris terbaca
while ((text = reader.readLine()) != null) {
contents.append(text).append(System.getProperty("l ine.separator"));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
// tampilkan isi file
System.out.println(contents.toString());
}
}
nah diatas kan ada file test.txt
filenya isinya ginian
Spoiler for test.txt:
Quote:
1 0.002188 0.000000 0.000000 0.620521
2 0.002917 0.315417 0.188854 0.004440
3 0.000313 0.009825 0.008978 0.663125
4 0.111667 0.123855 0.078230 0.663125
ane punya array[i][j]
dengan i = indeks data 1,2,3,4
dan j = indeks data 0.00 dst
pertanyaannya....gmn ya supaya angka di test.txt bs masuk ke var array...
tolong bgt ya agan2...
penting bgt sebabnya ini...
thx before..
</div>