Writing to file

Hello, long time no see lol forgot my password and wasn't sure the email I used. :) glad I figured it out. Now to the question.

I have a program that is reading email addresses from a file and printing the name onto another file. It seems to work properly but, it keeps skipping the first letter of the first email.

ReadandWrite.java
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;

public class ReadAndWrite {

	public static void main(String args[])
		throws FileNotFoundException {
			Scanner diskScanner = new Scanner(new File("email.txt"));
			PrintStream diskWriter = new PrintStream ("username.txt");
			char symbol;
			
			symbol = diskScanner.findWithinHorizon(".", 0).charAt(0);
			
			while(diskScanner.hasNext()){ //hasNext is to check if their is anything beyond the text in this case beyond @
			
				symbol = diskScanner.findWithinHorizon(".", 0).charAt(0);
				
			while (symbol !='@'){
				diskWriter.print(symbol);
				symbol = diskScanner.findWithinHorizon(".", 0).charAt(0);
			}
			diskScanner.nextLine();
			diskWriter.println();
			}
	}
}

email.txt

username.txt
oshuaparsons18
joshparsons253
jackparkerjilly
ancientpandas
gailsm4

Comments

  • Fixed. It's because I was reading in a character before the loop at line 19. So I deleted and left the two diskScanners and it is fully functional now.
Sign In or Register to comment.