🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: aus.computers.java
1 messages
1 total messages Started by John Fu Thu, 04 Nov 1999 00:00
Can somebody help with mine too!? I'm desperate!
#1052
Author: John Fu
Date: Thu, 04 Nov 1999 00:00
160 lines
5259 bytes
This is a multi-part message in MIME format.
--------------6FAEE4B040F51AE4ECC40C77
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

The main purpose of my assignment is to create a program that would
allow user input, choosing which letter to print.  The letters are in
.txt formats.  And at the same time, use the records read in from a user
inputted filename and use fields in the record file to replace the
placeholders in the letter files.

I could create the file, however, the letters created holds nothing!

Somebody please tell me what's going wrong in my code.

Thank you.

I have attached the source... Please.. somebody help....

John.




--------------6FAEE4B040F51AE4ECC40C77
Content-Type: text/plain; charset=us-ascii;
 name="Junk.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="Junk.java"

import java.*;
import java.io.*;


class Junk {
	
	static String RecordIn;
	static String LetterIn;
	static String Title, FName, LName, Street, Suburb, State, Postcode;
	
	static void userInput() throws IOException {
		
		BufferedReader UserIn = new BufferedReader (new InputStreamReader (System.in));
		
		System.out.print ("Please type in Record file name: ");
		RecordIn = UserIn.readLine();
		System.out.print ("Please type in Letter file name: ");
		LetterIn = UserIn.readLine();
	}//end userInput
	
	
	static void WriteLetter() throws IOException {
	
		int CharCount = 0;
		int Flag = 1;
		String OutFile;
		String Temp = "";
		OutFile = FName + ".txt";
		
		FileReader InL = new FileReader(LetterIn); //open letter file
		FileWriter Out = new FileWriter(OutFile);
		
		while ((CharCount = InL.read()) != -1) { //while not end of letter file
		
			if ((char)CharCount == '<') //new place holder found
				Flag = 2;
				
			else if ((Flag == 2)&&((char)CharCount != '>'))
				Temp = Temp + (char)CharCount;
				
			else if ((Flag == 1)&&((char)CharCount != '<')) //when not up to place holder
				Out.print((char)CharCount);
				
			else {  
				//when Flag=2 && Char = '>'
				
				if (Temp.equals("Title"))
					Out.print(Title);
				else if (Temp.equals("FName"))
					Out.print(FName);
				else if (Temp.equals("LName"))
					Out.print(LName);
				else if (Temp.equals("Street"))
					Out.print(Street);
				else if (Temp.equals("Suburb"))
					Out.print(Suburb);
				else if (Temp.equals("State"))
					Out.print(State);
				else //if Temp.equals("Postcode")
					Out.print(Postcode);
			}//end if
			Out.close();
		}//end while
	}//end WriteLetter()
		
		public static void main (String args[]) throws IOException, FileNotFoundException {
			
			String Storage;
			
			userInput(); //calls userInput module
			
			try { //need to try because file could be invalid
					FileReader InR = new FileReader(RecordIn); }//end try
					
			catch (FileNotFoundException e){ //need to catch error if invalid
					System.out.println("The record file "+RecordIn+" cannot be found.\nProgram exit");
					System.exit(0);
			}//end catch
			
			try {
					FileReader InL = new FileReader(LetterIn); }//end try
					
			catch (FileNotFoundException e) {
					System.out.println("The letter file "+LetterIn+" cannot be found. \nProgram exit.");
					System.exit(0);
			}//end catch		
			
			//see if the record file is empty
			
			FileReader InR1 = new FileReader(RecordIn); 
			BufferedReader br1 = new BufferedReader(InR1);
			
			if ((Storage = br1.readLine())==null) {
				System.out.println("The Record file "+RecordIn+" is empty.\nProgram exit");
				System.exit(0);
			}//end if	
			
			//see if the letter file is empty
			
			FileReader InL1 = new FileReader(LetterIn);
			BufferedReader br2 = new BufferedReader(InL1);
			
			if ((Storage = br2.readLine())==null) {
				System.out.println("The Letter file "+LetterIn+" is empty.\nProgram exit");
				System.exit(0);
			}//end if
			
			//now read the records
			System.out.println("The files are processing.......");
			
			FileReader InR2 = new FileReader(RecordIn);
			BufferedReader DB = new BufferedReader(InR2);
			
			while ((Storage = DB.readLine()) != null) { //while not end of file
				Title = Storage.substring(0,8).trim();
				FName = Storage.substring(8,18).trim();
				LName = Storage.substring(18,28).trim();
				Street = Storage.substring(28,58).trim();
				Suburb = Storage.substring(58,78).trim();
				State = Storage.substring(78,88).trim();
				Postcode = Storage.substring(88,92).trim();
				//now that the fields have been declared, write the letter
				WriteLetter();
				
			}//end while
			
		}//main
}//class Junk
--------------6FAEE4B040F51AE4ECC40C77--
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads