File tree 11 files changed +140
-66
lines changed
11 files changed +140
-66
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ public static void main(String[] args) {
18
18
Scanner sc = new Scanner (System .in );
19
19
String nombre = "" ;
20
20
String passwd = "" ;
21
- boolean valido = true ;
21
+ boolean authentication = true ;
22
22
23
23
try {
24
24
// Pedir los datos para el login
@@ -29,15 +29,15 @@ public static void main(String[] args) {
29
29
30
30
// Lanzar el método login
31
31
if (!login (nombre , passwd )) {
32
- valido = false ;
32
+ authentication = false ;
33
33
throw new ErrorLoginException ();
34
34
}
35
35
} catch (ErrorLoginException error ) {
36
36
// Código que se ejecutará si el código del bloque try lanza una excepción
37
37
System .out .println (error .getMessage ());
38
38
} finally {
39
39
// Código que se va ejecutar siempre (aunque se entre en el catch)
40
- if (valido ) {
40
+ if (authentication ) {
41
41
System .out .println ("Wellcome " + nombre );
42
42
} else {
43
43
System .out .println ("reboot app and try again" );
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 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
- }}
Original file line number Diff line number Diff line change
1
+
2
+ 2024-07-19 18:23:16
3
+ 2024-07-19 18:23:29
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ public static void main(String[] args) {
18
18
Scanner sc = new Scanner (System .in );
19
19
String nombre = "" ;
20
20
String passwd = "" ;
21
- boolean valido = true ;
21
+ boolean authentication = true ;
22
22
23
23
try {
24
24
// Pedir los datos para el login
@@ -29,15 +29,15 @@ public static void main(String[] args) {
29
29
30
30
// Lanzar el método login
31
31
if (!login (nombre , passwd )) {
32
- valido = false ;
32
+ authentication = false ;
33
33
throw new ErrorLoginException ();
34
34
}
35
35
} catch (ErrorLoginException error ) {
36
36
// Código que se ejecutará si el código del bloque try lanza una excepción
37
37
System .out .println (error .getMessage ());
38
38
} finally {
39
39
// Código que se va ejecutar siempre (aunque se entre en el catch)
40
- if (valido ) {
40
+ if (authentication ) {
41
41
System .out .println ("Wellcome " + nombre );
42
42
} else {
43
43
System .out .println ("reboot app and try again" );
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
1
+
2
+ 2024-07-22 09:04:14
3
+ 2024-07-22 09:04:49
Original file line number Diff line number Diff line change 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
- }}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
1
+
2
+ 2024-07-20 17:35:14
You can’t perform that action at this time.
0 commit comments