require 'sinatra'
get '/' do # Путь '/' означает корневой путь в URL.
"Hello World!"
end
ruby hello.rb
SwingUtilities.invokeLater(new Runnable() {
// TODO
})
public class Reader {
private List<User> users = new ArrayList<User>();
public void read(String path) {
BufferedReader readFromFile = null;
try {
readFromFile = new BufferedReader(new FileReader(path));
String line = null;
while ((line = readFromFile.readLine()) != null) {
User newUser = new User(line);
users.add(newUser);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (readFromFile != null)
try {
readFromFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public int calculateSum() {
int sum = 0;
for (User user : users) {
sum += user.getKey();
}
return sum;
}
private class User {
public int key = 0;
public String value;
public User(String line) {
if (line != null && !line.isEmpty()) {
String[] entries = line.split("\\s", 2);
this.key = Integer.valueOf(entries[0]); // можно завернуть в
// try {} catch
this.value = entries[1];
} else {
// логируем
}
}
public int getKey() {
return key;
}
public String getValue() {
return value;
}
}
public static void main(String[] args) {
Reader reader = new Reader();
reader.read("src//1.txt");
System.out.println(reader.calculateSum());
}
}