Alex86fire 0 Newbie Poster

I really need some help please, I really can't figure out how to do this.

I have to take some commands from system.in and put them in a file. when the command 'print' appears I need to read that file and process it. after that I have to be able to still get commands until next print when I process it again or until the command 'quit'.

Until now I can take the commands into the file until first print and I exit the loop on quit, but I can't figure out how to continue with the commands after the first print.

public static void main(String[] args) throws IOException {

		File printFile = new File("c:\\out.txt");
		File inFile= new File("c:\\test.txt");
		FileWriter outFile=null;
		try {
			outFile = new FileWriter(inFile);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		PrintWriter out = new PrintWriter(outFile);

		Scanner s = null;
		s = new Scanner(System.in);
		String comanda=null;

		if(!printFile.exists()){
			printFile.createNewFile();
		}
		int x = 1;

		while(x==1) 
		{
			comanda = s.nextLine();
			if(comanda.equals("print"))
			{
				out.println(comanda);
				out.close();
				FileHandle.procFile("c:\\test.txt");
				try {
					readFile(printFile);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			else
				if(comanda.equals("quit"))
					x=0;
				else
					out.println(comanda);
		}

		out.close();
		s.close(); 




		inFile.delete();
		printFile.delete();

	}

}
Be a part of the DaniWeb community

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