Soluzione 8.1

Da notare:
import java.io.FileReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Scanner;

public class StackQueueTester
{
    public static void main(String[] args) throws IOException
    {
        if (args.length != 3) //controllo che da riga di comando siano state
        {                     //passate esattamente tre stringhe
            System.out.println("uso: $java StackQueueTester file1 file2 file3");
            System.exit(1);
        }
      
        // Inserimento elementi da file nella pila e nella coda
        Scanner in = new Scanner(new FileReader(args[0]));
        Stack pila = new ArrayStack();
        Queue coda = new ArrayQueue();
        while (in.hasNextLine())
        {  Scanner sc = new Scanner(in.nextLine());
            while (sc.hasNext())
            {   String token = sc.next();
                pila.push(token);
                coda.enqueue(token);
            }
        }
        in.close();
      
        // Svuotamento di pila e coda, e scrittura su file
        PrintWriter writer1 = new PrintWriter(args[1]);
        PrintWriter writer2 = new PrintWriter(args[2]);

        while (!pila.isEmpty())
            writer1.println((String)pila.pop()); 
        while (!coda.isEmpty())
            writer2.println((String)coda.dequeue()); 

        writer1.close();
        writer2.close();
    }
}