hello im trying to take my values in my text file input, and store them in an array then parse those values into usable data and then store those values in a new array. I have the reading of the file but for some reason i cant seem to gain access to the values correctly, i try to parse the values or remove elements but it doesnt seem to change anything in my output when i print the changed array.
please let me know what part im messing up on
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
public class dataminingp1
{
String[] data = new String[100];
String line;
public void readf() throws IOException
{
FileReader fr = new FileReader("C:\\input.txt");
BufferedReader br = new BufferedReader(fr);
int i = 0;
while ((line = br.readLine()) != null)
{
data[i] = line;
System.out.println(data[i]);
i++;
}
br.close();
System.out.println("Data length: "+data.length);
String[][] root;
List<String> lines = Files.readAllLines(Paths.get("input.txt"), StandardCharsets.UTF_8);
root = new String[lines.size()][];
lines.removeAll(Arrays.asList("", null)); // <- remove empty lines
for(int a =0; a<lines.size(); a++)
{
root[a] = lines.get(a).split(" ");
}
lines.get(0).replace(',', ' ');
//int p = Integer.parseInt(root[0][0]);
System.out.println(lines.get(0));
//System.out.println(p);
}
public static void main(String[] args) throws IOException
{
dataminingp1 sarray = new dataminingp1();
sarray.readf();
}
}
please include any at all sources for any help you give, thank you very much in advance. I really appreciate it.
lines.get(0).replace(',', ' ');String is immutable. Put the result of the replace method back into the list e.g.lines.set(0, lines.get(0).replace(',', ' '));