Hallo Leute,
direkt nochmal eine Fehlersuche von mir
Folgende Aufgabe:
Write a program that reads integers from a text file. The program writes out the positive integers in the input file to one output file and the negative integers to a second output file. Prompt the user for the names of all three files.
Soweit so gut, ier mein Code soweit:
import java.util.Scanner;
import java.io.*;
public class Ex3
{
public static void main(String[] args) throws Exception
{
//input anfordern
String inputname;
Scanner scanName = new Scanner(System.in);
System.out.println("Datei fuer den Input eingeben: ");
inputname = scanName.nextLine().trim();
File input = new File(inputname);
//Scanner fuer input
Scanner scan = new Scanner(input);
//output 1 und 2 anfordern
String nameoutput1, nameoutput2;
System.out.println("Dateinamen fuer den Output positiver Integer eingeben:");
nameoutput1 = scanName.nextLine();
File output1 = new File(nameoutput1);
System.out.println("Dateinamen fuer den Output negativer Integer eingeben:");
nameoutput2 = scanName.nextLine();
File output2 = new File(nameoutput2);
//Printstream fuer output
PrintStream print1 = new PrintStream(output1);
PrintStream print2 = new PrintStream(output2);
int wert;
while(scan.hasNextInt());
{
if (scan.nextInt() >= 0)
{
wert = scan.nextInt();
print1.println(wert);
}
else
{
print2.println(scan.nextInt());
}
}
print1.close();
print2.close();
}
}
Die input Datei ist dieses Mal auf jeden Fall richtig, sie enthält nur Integer, da kann man ja nicht viel falsch machen denke ich ^^
Wenn ich das Programm ausführe dann fragt die Console brav nach den 3 Dateinamen, und bleibt dann hängen, bzw macht nichts mehr...
Die beiden output dateien werden zwar erstellt, sind aber leer.
Probiere seit 30 min rum aber finde das Problem einfach nicht.
Wäre nett wenn jemand mir weiterhelfen könnte.
direkt nochmal eine Fehlersuche von mir
Folgende Aufgabe:
Write a program that reads integers from a text file. The program writes out the positive integers in the input file to one output file and the negative integers to a second output file. Prompt the user for the names of all three files.
Soweit so gut, ier mein Code soweit:
import java.util.Scanner;
import java.io.*;
public class Ex3
{
public static void main(String[] args) throws Exception
{
//input anfordern
String inputname;
Scanner scanName = new Scanner(System.in);
System.out.println("Datei fuer den Input eingeben: ");
inputname = scanName.nextLine().trim();
File input = new File(inputname);
//Scanner fuer input
Scanner scan = new Scanner(input);
//output 1 und 2 anfordern
String nameoutput1, nameoutput2;
System.out.println("Dateinamen fuer den Output positiver Integer eingeben:");
nameoutput1 = scanName.nextLine();
File output1 = new File(nameoutput1);
System.out.println("Dateinamen fuer den Output negativer Integer eingeben:");
nameoutput2 = scanName.nextLine();
File output2 = new File(nameoutput2);
//Printstream fuer output
PrintStream print1 = new PrintStream(output1);
PrintStream print2 = new PrintStream(output2);
int wert;
while(scan.hasNextInt());
{
if (scan.nextInt() >= 0)
{
wert = scan.nextInt();
print1.println(wert);
}
else
{
print2.println(scan.nextInt());
}
}
print1.close();
print2.close();
}
}
Die input Datei ist dieses Mal auf jeden Fall richtig, sie enthält nur Integer, da kann man ja nicht viel falsch machen denke ich ^^
Wenn ich das Programm ausführe dann fragt die Console brav nach den 3 Dateinamen, und bleibt dann hängen, bzw macht nichts mehr...
Die beiden output dateien werden zwar erstellt, sind aber leer.
Probiere seit 30 min rum aber finde das Problem einfach nicht.
Wäre nett wenn jemand mir weiterhelfen könnte.