Skip to content

Instantly share code, notes, and snippets.

@azisaka
Created October 23, 2010 21:33
Show Gist options
  • Save azisaka/642720 to your computer and use it in GitHub Desktop.
Save azisaka/642720 to your computer and use it in GitHub Desktop.
FileRead.java
BH 0 472 281 315 511 - - 435 544 483
PC 472 0 443 827 - - - - - 677
JF 281 443 0 453 - - - - - -
GV 315 827 453 0 - 486 - - - -
PA 511 - - - 0 - - 466 319 -
SL - - - 486 - 0 - 222 - -
JN - - - - - - 0 138 - -
MC 435 - - - 466 222 138 0 629 -
UL 544 - - - 319 - - 629 0 107
require 'pp'
cities = {}
File.open(File.dirname(__FILE__) + "/distance.txt").readlines.each_with_index do |line, index|
columns = line.split(/\s+/)
cities[columns.shift] = {
:index => index,
:distance => columns.map { |c| c =~ /\-/ ? nil : c.to_i }
}
end
pp cities
import java.io.*;
import java.util.*;
class FileRead {
public static void main(String args[]) {
try {
FileInputStream file_stream = new FileInputStream("distance.txt");
DataInputStream input_stream = new DataInputStream(file_stream);
BufferedReader buffer = new BufferedReader(new InputStreamReader(input_stream));
String line;
Hashtable cities = new Hashtable();
while((line = buffer.readLine()) != null) {
String[] splitted_points = line.split(" ");
for(int i = 1; i < 10; i++)
cities.put(splitted_points[0], splitted_points[i]);
}
input_stream.close();
String[] points = cities.get("BH");
for(int j = 0; j < points.length; j++)
System.out.println("Distance: " + cities.get("BH"));
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment