I have assignment that requires us to read from a text file of covid 19 codon sequences. I have read in the first line as a string. I am able to convert this one line into 3 character substrings. However, my issue is now to do this for the rest of the file. When I add a hasNext method, it doesn't seem to work the same as my testline.
{
//Open the file
File file = new File("D://Downloads/covid19sequence.txt");
Scanner scan = new Scanner(file); String testLine = ""; String contents = ""; String codon2 = "";
double aTotal, lTotal, lPercentage;
ArrayList<String> codonList = new ArrayList<String>();
//Read a line in from the file and assign codons via substring
testLine = scan.nextLine();
for (int i = 0; i < testLine.length(); i += 3)
{
String codon = testLine.substring(i, i + 3);
codonList.add(codon);
}
while(scan.hasNext())
System.out.println(codonList);
}
For reference here is the output for the testline:
[AGA, TCT, GTT, CTC, TAA, ACG, AAC, TTT, AAA, ATC, TGT, GTG, GCT, GTC, ACT, CGG, CTG, CAT, GCT, TAG]