If the problem is that is not printing all lines of the file, you are overriding the array on loop. You should edit your question, because the array is working, the really problem is that the file wasn't printing all lines.
Here's the solution for name,number format:
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Teste {
public static void main(String[] args) throws IOException {
Teste x = new Teste();
x.doTeste();
}
public void doTeste() throws IOException{
String fileName = "D:\\Projetos\\Testes\\src\\teste.txt";
BufferedReader in = null;
try{
File csvfile = new File(fileName);
FileInputStream csvStream = new FileInputStream(csvfile);
in = new BufferedReader(new InputStreamReader(csvStream));
String line;
String[] rowName = new String[(countLines(fileName)+1)];
String[] rowNameData = new String[(countLines(fileName)+1)];
int linha = 0;
while ((line = in.readLine()) != null){
String[] array = line.split(",");
rowName[linha] = array[0];
rowNameData[linha] = array[1];
++linha;
}
System.out.println("The rowName ARRAY");
for (String s: rowName){
System.out.println(s);
}
System.out.println("The rowNameData ARRAY");
for (String s: rowNameData){
System.out.println(s);
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally {
in.close();
}
}
public static int countLines(String filename) throws IOException {
InputStream is = new BufferedInputStream(new FileInputStream(filename));
try {
byte[] c = new byte[1024];
int count = 0;
int readChars = 0;
boolean empty = true;
while ((readChars = is.read(c)) != -1) {
empty = false;
for (int i = 0; i < readChars; ++i) {
if (c[i] == '\n') {
++count;
}
}
}
return (count == 0 && !empty) ? 1 : count;
} finally {
is.close();
}
}
}
and for name in one line, and number the next line:
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Teste {
public static void main(String[] args) throws IOException {
Teste x = new Teste();
x.doTeste();
}
public void doTeste() throws IOException{
String fileName = "D:\\Projetos\\Testes\\src\\teste.txt";
BufferedReader in = null;
try{
File csvfile = new File(fileName);
FileInputStream csvStream = new FileInputStream(csvfile);
in = new BufferedReader(new InputStreamReader(csvStream));
String line;
String[] rowName = new String[(countLines(fileName)+1)/2];
String[] rowNameData = new String[(countLines(fileName)+1)/2];
int iCount=0;
int x = 0;
int y = 0;
while ((line = in.readLine()) != null){
if (iCount == 0 || iCount%2 == 0) {
rowName[x] = line;
++x;
}
else {
rowNameData[y] = line;
++y;
}
iCount++;
}
System.out.println("The rowName ARRAY");
for (String s: rowName){
System.out.println(s);
}
System.out.println("The rowNameData ARRAY");
for (String s: rowNameData){
System.out.println(s);
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally {
in.close();
}
}
public static int countLines(String filename) throws IOException {
InputStream is = new BufferedInputStream(new FileInputStream(filename));
try {
byte[] c = new byte[1024];
int count = 0;
int readChars = 0;
boolean empty = true;
while ((readChars = is.read(c)) != -1) {
empty = false;
for (int i = 0; i < readChars; ++i) {
if (c[i] == '\n') {
++count;
}
}
}
return (count == 0 && !empty) ? 1 : count;
} finally {
is.close();
}
}
}