import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Main {
public Main() {
File folder1 = new File("ordner");
File file1 = new File("ordner/Protokoll.txt");
double answer;
double anfangswert;
boolean check = false;
if(folder1.exists()) {
System.out.println("Ordner existiert");
}else {
folder1.mkdirs();
System.out.println("Ordner wird erstellt");
}
if(file1.exists()) {
System.out.println("Datei existiert");
}else {
try {
file1.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
Scanner sc = new Scanner(file1);
while(sc.hasNext()) {
System.out.print(sc.next() + " ");
}
System.out.println("");
sc.close();
} catch (FileNotFoundException e) {
System.out.println("Datei ist nicht da");
e.printStackTrace();
}
try {
OutputStream stream = new FileOutputStream(file1);
String textinhalt = "";
try {
stream.write(textinhalt.getBytes());
stream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
System.out.println("Datei gibt es nicht");
e.printStackTrace();
}
while(check == false) {
System.out.print("Was ist ihr Standardwert: ");
Scanner a = new Scanner(System.in);
answer = a.nextInt();
if(answer > 0) {
System.out.println("Ok der Standardwert wir auf " + answer + " gesetzt");
anfangswert = answer;
check = true;
try {
OutputStream stream = new FileOutputStream(file1);
stream.write(anfangswert);
stream.close();
} catch (FileNotFoundException e) {
System.out.println("Datei gibt es nicht");
e.printStackTrace();
}
}else {
System.out.println("Es kann keine Zahl unter 0 sein oder Buchstaben");
}
}
}
public static void main(String[] args) {
Date currentlyDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
String formattedDate =sdf.format(currentlyDate);
System.out.println(formattedDate);
Date currentlyDate1 = new Date();
SimpleDateFormat adf = new SimpleDateFormat("HH.mm.ss");
String formattedDate1 =adf.format(currentlyDate1);
System.out.println(formattedDate1);
new Main();
}
}
String letzteZahl = null;
try {
Scanner sc = new Scanner(file1);
while(sc.hasNext()) {
letzteZahl = sc.next();
System.out.print(letzteZahl + " ");
}
System.out.println("");
sc.close();
} catch (FileNotFoundException e) {
System.out.println("Datei ist nicht da");
e.printStackTrace();
}
// hier ist letzteZahl die letzte gelesene Zahl oder null, falls nichts gelesen wurde.
try {
Scanner sc = new Scanner(file1);
while(sc.hasNext()) {
System.out.print(sc.next() + " ");
}
System.out.println("");
sc.close();
} catch (FileNotFoundException e) {
System.out.println("Datei ist nicht da");
e.printStackTrace();
}