Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Java is simple to read and write HDFS Demo     - Install Websphere MB required system rpm package under Linux (Linux)

- Python 3 for instructions encoded string conversion (Programming)

- Linux common network tools: batch scanning of hosting services netcat (Linux)

- MySQL multi-master-slave synchronization (Database)

- Linux iptables firewall and vsftpd to resolve the issue (Linux)

- History of the most complex validation e-mail address regular expression (Linux)

- Orabbix binding Python send graphical reports (Linux)

- Debian 7 and Debian 8 users how to install Oracle Java 8 (Linux)

- Linux system man help tips (Linux)

- MySQL binlog group to submit XA (two-phase commit) (Database)

- cp: omitting directory error solutions under Linux (Linux)

- Grep, Ack, Ag searches Efficiency Comparison (Linux)

- Hyper-V virtual hard disk how to copy files to and attached to the virtual machine (Linux)

- expdp / impdp use version parameter data migration across versions (Database)

- Spring loaded container finishes executing a method (Programming)

- How to recover deleted files in Linux systems (Linux)

- Install mono offline on CentOS (Server)

- RPM package management tools under Linux (Linux)

- Delete specific files using bash directory under Linux (Linux)

- C # / iOS / Android Universal Encryption and decryption (Programming)

  Java is simple to read and write HDFS Demo
  Add Date : 2018-11-21      
  Environment: Eclipse + Eclipse Hadoop plug, Hadoop + RHEL6.4

Java is simple to read and write HDFS Demo

package test;

import java.io.IOException;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream ;;

public class Test {
 public void WriteFile (String hdfs) throws IOException {
  Configuration conf = new Configuration ();
  FileSystem fs = FileSystem.get (URI.create (hdfs), conf);
  FSDataOutputStream hdfsOutStream = fs.create (new Path (hdfs));
  hdfsOutStream.writeChars ( "hello");
  hdfsOutStream.close ();
  fs.close ();
 public void ReadFile (String hdfs) throws IOException {
  Configuration conf = new Configuration ();
  FileSystem fs = FileSystem.get (URI.create (hdfs), conf);
  FSDataInputStream hdfsInStream = fs.open (new Path (hdfs));
  byte [] ioBuffer = new byte [1024];
  int readLen = hdfsInStream.read (ioBuffer);
  while (readLen = -! 1)
   System.out.write (ioBuffer, 0, readLen);
   readLen = hdfsInStream.read (ioBuffer);
  hdfsInStream.close ();
  fs.close ();
 public static void main (String [] args) throws IOException {
  String hdfs = "hdfs: // 9000 / test / hello.txt";
  Test t = new Test ();
  t.WriteFile (hdfs);
  t.ReadFile (hdfs);
- Ubuntu method for single-card dual-IP (Linux)
- Sorting Algorithm (1) Quick Sort C ++ implementation (Programming)
- C ++ CBitmap, HBitmap, Bitmap difference and contact (Programming)
- PHP 7.0 Upgrade Notes (Linux)
- Android components series Activity (Programming)
- Linux program analysis tool: ldd and nm (Linux)
- Linux hybrid character device (Linux)
- High-performance open-source http accelerator Varnish introduce (Server)
- Linux Network Programming - libnet Guide (Programming)
- OpenVPN offsite interconnecting room availability and load balancing solution (Server)
- Learning MySQL data types (Database)
- REDO LOG records management (Database)
- Ubuntu Apache2 setting, problem solving css, pictures, etc. can not be displayed (Server)
- PuTTY Xming achieve the X11 forwarding ssh (Server)
- Adding SSH to Github (Linux)
- Node.js developers must know four JavaScript concepts (Programming)
- Linux --- manual release system cache (Linux)
- CentOS 6.6 compile and install phpMyAdmin configuration PostgreSQL9.4.1 (Database)
- Installation Enpass secure password manager on Ubuntu (Linux)
- CentOS 6.5 upgrade to CentOS 7 (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.