For the first part, simply read in the rowcount
number from the first file and compare to the line count from the second file.
For the second part, read in delim
and then use a Scanner
or similar to read the second file using delim
as your delimiter. If you only want a single character in between each delimiter, then test for this as you read the file, and throw an exception if you see more than a single character being read in.
From the example link:
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class MainClass {
public static void main(String args[]) throws IOException {
char[] chars = new char[100]; //If you know how many you want to read
//(if not, use an ArrayList or similar)
FileReader fin = new FileReader("Test.txt");
Scanner src = new Scanner(fin);
// Set delimiters to newline and pipe ("|")
//Use newline character OR (bitwise OR is "|") pipe "|" character
//since pipe is also OR (thus a meta character), you must escape it (double backslash)
src.useDelimiter(src.useDelimiter(System.getProperty("line.separator")+"|\\|");
// Read chars
for(int i = 0; src.hasNext(); i++) {
String temp = src.next();
if(temp.length != 1)
System.out.println("Error, non char"); //Deal with as you see fit
chars[i] = temp.charAt(0); //Get first (and only) character of temp
}
fin.close();
//At this point, chars should hold all your data
}
}