|
| |||||||||
| Tags: file, file system, matrix, permissions, read, write |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Read file to create a matrix
Hello, I want to read a file to create a two-dimensional array and store the size of this table. I created a class matrix. In another method constMat class. I am getting any error in my code, this is my code, please have a look at it. Code: Public static Matrix ConstMat(String path){
int t =0;
int s =0;
BufferedReader file;
try {
file = new BufferedReader(new FileReader(path));
try {
String ln1;
ln1 = file.readln();
s = Integer.function valueOf() {
[native code]
}(ln1);
Matrix m1 = new Matrix(s);
while(file.read()!=-1){
if(Turn! =0){
int i =0;
String ln;
ln = file.readln();
StringTokenizer st = new StringTokenizer(row," ");
while (st.hasMoreTokens()){
int con;
con = Integer.function valueOf() {
[native code]
}(st.nextToken());
m1.SetCell(con, t, i);
i + +;
}
t + +;
}
}
} catch (NumberFormException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ret m1;
} |
|
#2
| |||
| |||
| Re: java code for two dimensional array
Hello, I have not clearly understood what exactly are you trying to do here. But my suggestion for you is Code: if(Turn! =0) |
|
#3
| |||
| |||
| Re: Read file to create a matrix
Hello, you must define your matrix before you are doing the rest. I mean to say, take a look at the example below Code: Public static Matrix ConstMat(String path){
int con =0;
int s =0;
BufferedReader file;
Matrix m1 |
|
#4
| |||
| |||
| Re: Read file to create two dimensional array
Hello, This is my matrix class, please check and if you find any problem in the clas then please guide me with the correct one. Code: Public class Matrix {
int tmp;
int[][] mt;
Public Matrix(int s){
tmp = s;
mt =new int[s][s];
}
Public void SetCell(int val, int row, int Pass){
mt[row][Pass]= val;
}
} |
|
#5
| |||
| |||
| Re: Read file to create a matrix
Hello, I think you can do it also with the ListIterator , though I am not sure of this because I have not tried it. Just have a look at the code and if you need then use it. Code: ListIterator li = list.listIterator ();
Object [] barr = new Object[i];
String [] str = new String[i];
while (li.hasNext()) {
barr[counter]=li.next();
str[counter]=barr[counter].toString();
counter++;
} |
|
#6
| |||
| |||
| Re: Read file to create a matrix
Hello, For creating a matrix you need to use the two dimensional array in your program and here is the example of the two dimensional array in java Code: int[][] t;
t = new int[10][]; // allocate array of rows
for (int r=0; r<t.length; r++) {
t[r] = new int[r+1];
}
// print the tangular array (same as above really)
for (int r=0; r<t.length; r++) {
for (int c=0; c<t[r].length; c++) {
System.out.print(" " + t[r][c]);
}
System.out.println("");
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Read file to create a matrix" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| New Matrix Movie (Matrix ReEntered) | Vicious | Off Topic Chat | 8 | 08-02-2011 08:24 PM |
| cannot delete file -- cannot read from source file or disk | Barry Karas | Windows XP Support | 3 | 11-11-2010 09:55 PM |
| Any fastest way to compute 3x3 Matrix inverse and Matrix multiplication? | Logan.B | Software Development | 4 | 25-09-2010 06:11 PM |
| How to create read write lock in java | AlienKing | Software Development | 3 | 05-05-2009 09:18 PM |
| XP: Cannot delete file: Cannot read from the source file or disk. | iexplorer0726 | Operating Systems | 0 | 10-09-2007 06:07 AM |