Ok. So I am working on a program that gets information that has been put into textfields in a gui and puts that information into a text file and the name of the file is the name of the animal and name of the owners last name.
//that part is done.
Then able to search for the file using the name of the animal and the owners last name, and being able to have the information be put into separate text fields. That look like the page where you first put down the information. Then being able to save the information changed to the same text file.
Now my question is how do I get the information from a text file that has different lines and then put each line in its own String.
Here is the part of the program that reads the text file
`import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;
public class ReadFile {
private String path;
public ReadFile(String file_path) {
path = file_path;
}
public String[] OpenFile() throws IOException {
FileReader fr = new FileReader (path);
BufferedReader textReader = new BufferedReader(fr);
int numberOfLines = 20;
String[] textData = new String[numberOfLines];
int i;
for (i=0; i < numberOfLines; i++) {
textData[i] = textReader.readLine();
}
textReader.close();
return textData;
}
int readLines() throws IOException {
FileReader file_to_read = new FileReader(path);
BufferedReader bf = new BufferedReader(file_to_read);
String aLine;
int numberOfLines = 0;
while (( aLine = bf.readLine()) != null) {
numberOfLines++;
}
bf.close();
return numberOfLines;
}
}
`
// Here is where I am using this code
`JButton b7 = new JButton("Done");
b7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
f4.setVisible(true);
f3.setVisible(false);
scrollPane.revalidate();
scrollPane.repaint();
String namess = names.getText();
na.setText(namess);
String ownerslss = ownersls.getText();
ol.setText(ownerslss);
String file_name =namess + " " + ownerslss + ".txt";
na.setText(namess);
ol.setText(ownerslss);
try {
ReadFile file = new ReadFile (file_name);
String [] aryLines = file.OpenFile();
String aryLiness ="";
int item, space;
for (item=0; item < aryLines.length; item++) {
System.out.println(aryLines[item]);
aryLiness = Arrays.toString(aryLines);
space = aryLines.length;
}
space = aryLines.length;
//< assname is a textarray that is the only way I could get the words to go down the page but it doesn't look good at all. Because it doesn't skip lines...
assname.setSize(20 ,space);
assname.append("" + aryLiness);
panimals.add(assname);
}
catch (IOException wewe) {
System.out.println(wewe.getMessage() );
}
}
});`