-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobotUtils.java
More file actions
108 lines (95 loc) · 3.04 KB
/
Copy pathRobotUtils.java
File metadata and controls
108 lines (95 loc) · 3.04 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.legrand.iln;
import java.io.*;
import java.util.*;
/**
* Progetto ILN
* Copyright (C) 2003 Monsieur Legrand
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the license, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/**
* Classe che implementa varie funzioni di utilita'
* per gli ILN.
*
* @author Monsieur Legrand
* @version 1.45rev 0
* @date 05 agosto 2017
*/
public class RobotUtils {
/**
* Legge i dati da un file di testo. La lettura avviene per righe.
*
* @param fileName stringa contenente il nome del file da leggere.
* l'estensione .txt viene aggiunta automaticamente.
*
* @return una Collection contenente tutte le stringhe lette dal file.
*/
public static Collection leggeDati(String fileName) {
Collection risposta = new ArrayList();
String lettura;
FileInputStream f = null;
InputStreamReader inp = null;
BufferedReader fIn = null;
try{
f = new FileInputStream(fileName + ".txt");
inp = new InputStreamReader(f);
fIn = new BufferedReader(inp);
}catch (IOException ex){
System.out.println("Errore nell'apertura del file:");
ex.printStackTrace();
System.exit(1);
}
try{
while ( (lettura = fIn.readLine()) != null )
risposta.add(lettura);
}catch(IOException ex){
System.out.println("Errore durante la lettura dal file:");
ex.printStackTrace();
System.exit(1);
}
try{
fIn.close();
inp.close();
f.close();
}catch(IOException ex){
System.out.println("Errore durante la chiusura del file:");
ex.printStackTrace();
System.exit(1);
}
return risposta;
}
/**
* Aggiunge un nuovo nome all'elenco dei nomi conosciuti dal programma.<br>
* Per nomi si intendono i nickname che gia' hanno interagito con il programma.
*
* @param arg una stringa contenente il nome del file contenente i nomi noti.
* L'estensione .txt viene aggiunta automaticamente.
* @param nick il nome/nickname da aggiungere.
*/
public static void aggiungiNome(String arg, String nick) {
FileWriter outStream;
PrintWriter out;
try{
outStream = new FileWriter(arg + ".txt", true);
out = new PrintWriter(outStream, true);
out.println(nick);
out.close();
outStream.close();
} catch(IOException ec){
System.out.println("Errore nell'accesso al file di nomi: " + arg + ".txt");
ec.printStackTrace();
}
}
}