有兴趣使用的请点下载链接
数据文件与源代码下载
1 从本地文件读数据,按行操作
String filePath = "/root/input_2";
File file=new File(filePath);
InputStreamReader in_stream = new InputStreamReader(new FileInputStream(file));
BufferedReader in = new BufferedReader(in_stream);
String s;
while ((s=in.readLine())!=null ) {
System.out.println(s);
}
2 Hbase 创建表并put
public class HBaseTest {
public static void main(String[] args) throws MasterNotRunningException,
ZooKeeperConnectionException, IOException {
// create table descriptor
String tableName= "mytable";
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
// create column descriptor
HColumnDescriptor cf = new HColumnDescriptor("mycf");
htd.addFamily(cf);
// configure HBase
Configuration configuration = HBaseConfiguration.create();
HBaseAdmin hAdmin = new HBaseAdmin(configuration);
hAdmin.createTable(htd);
hAdmin.close();
// put "mytable","abc","mycf:a","789"
HTable table = new HTable(configuration,tableName);
Put put = new Put("abc".getBytes());
put.add("mycf".getBytes(),"a".getBytes(),"789".getBytes());
table.put(put);
table.close();
System.out.println("put successfully");
}
}