adamleefe 0 Newbie Poster

Hey, so far i have created some code that reads a text file and outputs the information if i run it in eclipse and i now want to have an option when it runs to either show the information in plainscript or html, how would i do this does anyone know the code?

Thanks and any help is much welcomed and thanked.

Adam

import java.util.Scanner;
import java.io.FileNotFoundException; 
import java.io.File;
import java.io.FilenameFilter;

//The name of the file is generator
public class Generator 
{
	public static void main (String[] args)
	{
		//This finds the text files in my selected folder that are called .txt
		FilenameFilter filter = new FilenameFilter() 
		{
		    public boolean accept(File folder, String name) 
		    {
		    	 return name.endsWith(".txt"); //Return all files that end in .txt
		    }
		};
		//Current directory
		String curDir = System.getProperty("user.dir");
		File folder = new File(curDir);
		//This creates a DIR array that stores all files
		File[] dir = folder.listFiles(filter);

		//This helps the code show the files available with the .txt ending
		for (int i = 0; i < dir.length; i++) 
		{
		      if (dir[i].isFile()) 
		      {
		        System.out.println("File " + dir[i].getName());
		      }
		}
		
		//This produces some text with the file names and then asks to select one
		String file = "";
		System.out.print("Please select one of the files shown above: ");
		Scanner a = new Scanner(System.in);
		file = a.next();
		
		//This creates a new file based on the users input
		File fixtures = new File(file);

		try 
		{
			//Create the read line for scanner and create the scanner & counts - CREATES MOST THINGS
			String readline;
			Scanner scanner = new Scanner(fixtures);
			int total1 = 0;
			int total2= 0;
			int totalgoals = 0;
			int valid = 0;
			int invalid = 0;
					
			//Scanner reads the lines
			while (scanner.hasNext())
			{
				//Gets the line
				readline = scanner.nextLine();
				
				//This splits the lines and create an array
				String [] split = readline.split(" : ");
				
				if(split.length == 4) //amount of information
				{		
					//Store the strings -ADD TRIM - NEW !!!
					String HomeTeam = split [0];
					String HomeScore = split [2];
					String AwayTeam = split [1];
					String AwayScore = split [3];
					
					//Score the variables
					int iHomeScore = 0;
					int iAwayScore = 0;

					//Validation
					try
					{
						iHomeScore = Integer.parseInt(HomeScore);
						iAwayScore = Integer.parseInt(AwayScore);

						//Output the lines
						System.out.print(HomeTeam+" ");
						System.out.print("["+iHomeScore+"] | ");
						System.out.print(AwayTeam+" ");
						System.out.println("["+iAwayScore+"]");
						
						//Counting total goals and valid matches (It's already in a loop)
						total1 = total1 + iHomeScore;
						total2 = total2 + iAwayScore;
						totalgoals = total1+total2;
						valid = valid+1;
					}
					catch (NumberFormatException e) //catches  the information for teams and scores
					{
						//invalid needs to be incremented NEW!!!
					}
				}
				else
				{
					invalid = invalid+1;
				}
			}
			//Prints out the number of goals scored and number of valid matches
			System.out.println("\nTotal Goals Scored Were: "+totalgoals);
			System.out.println("Valid Match Count Was: " +valid);
			if (invalid > 0) // If they are invalid
			{
				//Prints the number of invalid matches
				System.out.print("Invalid Match Count Was: " +invalid);
			}
			
		}
		catch (FileNotFoundException exception1) //If file is not found
		{
			System.out.print("There was an issue with the file you selected, this may be due to spelling mistakes or the file doesnt exist. Please ensure the file name is correct.");
		}// If they enter a file name that doesn't exist
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.