-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPruebas.java
More file actions
76 lines (55 loc) · 1.41 KB
/
Pruebas.java
File metadata and controls
76 lines (55 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Pruebas {
public static void main(String[] args) {
//
//Hasta java 6
//
Connection cx = null;
Socket sk = null;
FileReader fr = null;
try {
cx = DriverManager.getConnection("","","");
sk = new Socket("ip",5000);
fr = new FileReader("datos.txt");
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
cx.close();
sk.close();
fr.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
//
//A partir de Java 7
//
try(Connection cx2 = DriverManager.getConnection("","","");
Socket sk2 = new Socket("ip",1000);
FileReader fr2 = new FileReader("datos.dat")){
//Nuestro código
} catch (SQLException | FileNotFoundException | UnknownHostException e) {
//No podemos agrupar en un mismo multicatch excepciones en la
//misma rama de herencia
e.printStackTrace();
} catch (IOException e ){
e.printStackTrace();
}
}
}