Skip to content

Commit fb95b17

Browse files
committed
.
.
1 parent 3ede841 commit fb95b17

File tree

11 files changed

+140
-66
lines changed

11 files changed

+140
-66
lines changed

eclipse/src/j0032_Throwable/Main.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void main(String[] args) {
1818
Scanner sc = new Scanner(System.in);
1919
String nombre = "";
2020
String passwd = "";
21-
boolean valido = true;
21+
boolean authentication = true;
2222

2323
try {
2424
// Pedir los datos para el login
@@ -29,15 +29,15 @@ public static void main(String[] args) {
2929

3030
// Lanzar el método login
3131
if (!login(nombre, passwd)) {
32-
valido = false;
32+
authentication = false;
3333
throw new ErrorLoginException();
3434
}
3535
} catch (ErrorLoginException error) {
3636
// Código que se ejecutará si el código del bloque try lanza una excepción
3737
System.out.println(error.getMessage());
3838
} finally {
3939
// Código que se va ejecutar siempre (aunque se entre en el catch)
40-
if (valido) {
40+
if (authentication) {
4141
System.out.println("Wellcome " + nombre);
4242
} else {
4343
System.out.println("reboot app and try again");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package j0034_In_Out_putStream;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileReader;
5+
import java.io.FileWriter;
6+
import java.io.IOException;
7+
import java.time.LocalDateTime;
8+
import java.time.format.DateTimeFormatter;
9+
10+
public class Main {
11+
public static final String pathFile = "src/j0034_In_Out_putStream/test.txt"; // Use final for constant path
12+
13+
public static void main(String[] args) {
14+
Leer leer = new Leer();
15+
Escribir escribir = new Escribir();
16+
escribir.escribir();
17+
leer.leer();
18+
}
19+
}
20+
21+
class Leer {
22+
public void leer() {
23+
try (FileReader doc = new FileReader(Main.pathFile);
24+
BufferedReader docBuffer = new BufferedReader(doc)) { // Use try-with-resources
25+
String txt;
26+
while ((txt = docBuffer.readLine()) != null) {
27+
System.out.println(txt);
28+
}
29+
} catch (IOException e) {
30+
System.out.println("File not found.");
31+
e.printStackTrace();
32+
}
33+
}
34+
}
35+
36+
class Escribir {
37+
public void escribir() {
38+
// Generate timestamp
39+
LocalDateTime now = LocalDateTime.now();
40+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
41+
String timestamp = "\n" + now.format(formatter);
42+
43+
try (FileWriter doc = new FileWriter(Main.pathFile, true)) { // Use try-with-resources
44+
doc.write(timestamp.toCharArray());
45+
} catch (IOException e) {
46+
e.printStackTrace();
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
2024-07-19 18:24:11
3+
2024-07-19 18:24:20
4+
2024-07-19 18:24:22
5+
2024-07-19 18:24:23
6+
2024-07-19 18:24:24
7+
2024-07-19 21:13:20
8+
2024-07-19 21:13:27
9+
2024-07-19 21:13:28
10+
2024-07-19 21:13:30
11+
2024-07-19 21:13:39
12+
2024-07-19 21:13:40
13+
2024-07-19 21:13:41
14+
2024-07-19 21:16:49
15+
2024-07-19 21:16:50
16+
2024-07-19 21:16:51
17+
2024-07-19 21:16:52
18+
2024-07-19 21:16:53
19+
2024-07-19 21:16:54
20+
2024-07-19 21:16:56

eclipse/src/test/Main.java

-30
Original file line numberDiff line numberDiff line change
@@ -1,30 +0,0 @@
1-
package test;
2-
3-
import java.util.Scanner;
4-
5-
public class Main{
6-
static boolean login(String user, String passwd){
7-
if(user.equals("admin") && passwd.equals("123")){
8-
return true;
9-
}
10-
else{ return false;}
11-
}
12-
13-
14-
public static void main(String[] args) {
15-
Scanner sc = new Scanner(System.in);
16-
String name = "";
17-
String pass = "";
18-
boolean valido = true;
19-
20-
try{
21-
System.out.println("user");
22-
name = sc.nextLine();
23-
System.out.println("pass");
24-
pass = sc.
25-
26-
}
27-
28-
29-
30-
}}

eclipse/src/test/test.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
2024-07-19 18:23:16
3+
2024-07-19 18:23:29

intelliJ/src/j0032_Throwable/Main.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void main(String[] args) {
1818
Scanner sc = new Scanner(System.in);
1919
String nombre = "";
2020
String passwd = "";
21-
boolean valido = true;
21+
boolean authentication = true;
2222

2323
try {
2424
// Pedir los datos para el login
@@ -29,15 +29,15 @@ public static void main(String[] args) {
2929

3030
// Lanzar el método login
3131
if (!login(nombre, passwd)) {
32-
valido = false;
32+
authentication = false;
3333
throw new ErrorLoginException();
3434
}
3535
} catch (ErrorLoginException error) {
3636
// Código que se ejecutará si el código del bloque try lanza una excepción
3737
System.out.println(error.getMessage());
3838
} finally {
3939
// Código que se va ejecutar siempre (aunque se entre en el catch)
40-
if (valido) {
40+
if (authentication) {
4141
System.out.println("Wellcome " + nombre);
4242
} else {
4343
System.out.println("reboot app and try again");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package j0034_In_Out_putStream;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileReader;
5+
import java.io.FileWriter;
6+
import java.io.IOException;
7+
import java.time.LocalDateTime;
8+
import java.time.format.DateTimeFormatter;
9+
10+
public class Main {
11+
public static final String pathFile = "src/j0034_In_Out_putStream/test.txt"; // Use final for constant path
12+
13+
public static void main(String[] args) {
14+
Leer leer = new Leer();
15+
Escribir escribir = new Escribir();
16+
escribir.escribir();
17+
leer.leer();
18+
19+
}
20+
}
21+
22+
class Leer {
23+
public void leer() {
24+
try (FileReader doc = new FileReader(Main.pathFile);
25+
BufferedReader docBuffer = new BufferedReader(doc)) {
26+
String txt;
27+
while ((txt = docBuffer.readLine()) != null) {
28+
System.out.println(txt);
29+
}
30+
} catch (IOException e) {
31+
System.out.println("File not found.");
32+
e.printStackTrace();
33+
}
34+
}
35+
}
36+
37+
class Escribir {
38+
public void escribir() {
39+
// Generate timestamp
40+
LocalDateTime now = LocalDateTime.now();
41+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
42+
String timestamp = "\n" + now.format(formatter);
43+
44+
try (FileWriter doc = new FileWriter(Main.pathFile, true)) {
45+
doc.write(timestamp.toCharArray());
46+
} catch (IOException e) {
47+
e.printStackTrace();
48+
}
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
2024-07-22 09:04:14
3+
2024-07-22 09:04:49

intelliJ/src/test/Main.java

-30
Original file line numberDiff line numberDiff line change
@@ -1,30 +0,0 @@
1-
package test;
2-
3-
import java.util.Scanner;
4-
5-
public class Main{
6-
static boolean login(String user, String passwd){
7-
if(user.equals("admin") && passwd.equals("123")){
8-
return true;
9-
}
10-
else{ return false;}
11-
}
12-
13-
14-
public static void main(String[] args) {
15-
Scanner sc = new Scanner(System.in);
16-
String name = "";
17-
String pass = "";
18-
boolean valido = true;
19-
20-
try{
21-
System.out.println("user");
22-
name = sc.nextLine();
23-
System.out.println("pass");
24-
pass = sc.
25-
26-
}
27-
28-
29-
30-
}}

intelliJ/src/test/test.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
2024-07-19 18:23:16
3+
2024-07-19 18:23:29
4+
2024-07-20 17:35:29
5+
2024-07-20 17:35:36
6+
2024-07-20 17:35:53
7+
2024-07-20 17:35:56

intelliJ/test.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
2024-07-20 17:35:14

0 commit comments

Comments
 (0)