Java - Only read first line of a file

java

Solution

If I understand you, then

String text = brTest.readLine();
// Stop. text is the first line.
System.out.println(text);
String[] strArray = text.split(",");
System.out.println(Arrays.toString(strArray));

Problem

I only want to read the first line of a text file and put that first line in a string array. This is what I have but its reading the whole file. ex text in myTextFile: ``` Header1,Header2,Header3,Header4,Header5 1,2,3,4,5 6,7,8,9,10 String line= System.getProperty("line.separator"); String strArray[] = new String[5]; String text = null; BufferedReader brTest = new BufferedReader(new FileReader(myTextFile)); text = brTest .readLine(); while (text != line) { System.out.println("text = " + text ); strArray= text.split(","); } ```

Original source

Related problems