package com.ibeifeng.hdfs.test.hdfs_demo;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Scanner;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class Client2 {
private static Scanner s = new Scanner( System.in);
public static void main(String[]args) throws Exception{
Configuration conf = new Configuration();
conf.set("fs.defaultFS","hdfs:// bd.zhucheng.com:8020");
conf.set("dfs.replication", "1");
FileSystem fs = FileSystem.get(conf);
int op = 0;
String str = null;
int flag = 1;
while(flag==1) {
System.out.println("输入选项: 1.新建 2.打开 3.编辑");
op = s.nextInt();
switch(op) {
case 1:
System.out.println("输入文件名:");
str = s.next();
if(str.startsWith("/")) {
Path path = new Path(str);
fs.create(path);
}else {
Path path = new Path("/"+str);
fs.create(path);
}
System.out.println("创建成功!");
break;
case 2:
System.out.println("输入文件名:");
str = s.next();
Path path = null;
if(str.startsWith("/"))path = new Path(str);
else path = new Path("/"+str);
FSDataInputStream inputStream = fs.open(path);
BufferedReader d = new BufferedReader(new InputStreamReader(inputStream));
System.out.println("内容为:");
while((str=d.readLine())!=null)System.out.println(str);
d.close();
inputStream.close();
break;
case 3:
System.out.println("输入文件名:");
str = s.next();
Path path3 = null;
if(str.startsWith("/"))path3 = new Path(str);
else path3 = new Path("/"+str);
System.out.println("输入编辑内容:");
str = s.nextLine();
String strt = "";
while(!strt.equals("bye")) {
strt = s.nextLine();
str += ("\n"+strt);
}
str = str.replaceAll("bye","");
int op3 = 2;
System.out.println("\n追加到 1.头 2.尾");
op3 = s.nextInt();
if(op3==1) {
FSDataInputStream inputStream3 = fs.open(path3);
String str3 = null;
try {
str3 = inputStream3.readUTF();
str = str + str3;
}catch(Exception e) {
str3 = "";
str = str +"\n"+ str3;
}
inputStream3.close();
fs.deleteOnExit(path3);
FSDataOutputStream outputStream = fs.create(path3);
outputStream.write(str.getBytes());
outputStream.close();
}else {
FSDataOutputStream outputStream = fs.append(path3);
outputStream.write(str.getBytes());
outputStream.close();
}
break;
case 100:flag = 0;fs.close();s.close();break;
default:break;
}
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Scanner;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class Client2 {
private static Scanner s = new Scanner( System.in);
public static void main(String[]args) throws Exception{
Configuration conf = new Configuration();
conf.set("fs.defaultFS","hdfs:// bd.zhucheng.com:8020");
conf.set("dfs.replication", "1");
FileSystem fs = FileSystem.get(conf);
int op = 0;
String str = null;
int flag = 1;
while(flag==1) {
System.out.println("输入选项: 1.新建 2.打开 3.编辑");
op = s.nextInt();
switch(op) {
case 1:
System.out.println("输入文件名:");
str = s.next();
if(str.startsWith("/")) {
Path path = new Path(str);
fs.create(path);
}else {
Path path = new Path("/"+str);
fs.create(path);
}
System.out.println("创建成功!");
break;
case 2:
System.out.println("输入文件名:");
str = s.next();
Path path = null;
if(str.startsWith("/"))path = new Path(str);
else path = new Path("/"+str);
FSDataInputStream inputStream = fs.open(path);
BufferedReader d = new BufferedReader(new InputStreamReader(inputStream));
System.out.println("内容为:");
while((str=d.readLine())!=null)System.out.println(str);
d.close();
inputStream.close();
break;
case 3:
System.out.println("输入文件名:");
str = s.next();
Path path3 = null;
if(str.startsWith("/"))path3 = new Path(str);
else path3 = new Path("/"+str);
System.out.println("输入编辑内容:");
str = s.nextLine();
String strt = "";
while(!strt.equals("bye")) {
strt = s.nextLine();
str += ("\n"+strt);
}
str = str.replaceAll("bye","");
int op3 = 2;
System.out.println("\n追加到 1.头 2.尾");
op3 = s.nextInt();
if(op3==1) {
FSDataInputStream inputStream3 = fs.open(path3);
String str3 = null;
try {
str3 = inputStream3.readUTF();
str = str + str3;
}catch(Exception e) {
str3 = "";
str = str +"\n"+ str3;
}
inputStream3.close();
fs.deleteOnExit(path3);
FSDataOutputStream outputStream = fs.create(path3);
outputStream.write(str.getBytes());
outputStream.close();
}else {
FSDataOutputStream outputStream = fs.append(path3);
outputStream.write(str.getBytes());
outputStream.close();
}
break;
case 100:flag = 0;fs.close();s.close();break;
default:break;
}
}
}
}
20:06:23
李✘✘ 2018/10/9 星期二 20:06:23
李✘✘ 2018/10/9 星期二 20:06:26
嗯嗯
李✘✘ 2018/10/9 星期二 20:06:29
好
21:29:49
李✘✘ 2018/10/9 星期二 21:29:49
你找到测试的代码了吗
你撤回了一条消息
李✘✘ 2018/10/9 星期二 21:30:01
组宣部~李嘉来 2018/10/9 星期二 21:30:53
凉了
李✘✘ 2018/10/9 星期二 21:30:59
咋啦
组宣部~李嘉来 2018/10/9 星期二 21:31:02
一个人跟一个人版本不一样
李✘✘ 2018/10/9 星期二 21:31:14
什么版本啊
组宣部~李嘉来 2018/10/9 星期二 21:31:17
季方给我的、他能用、我这用不了
组宣部~李嘉来 2018/10/9 星期二 21:31:23
hadoop2.7.4
李✘✘ 2018/10/9 星期二 21:31:30
他有没有弄什么插件啊
李✘✘ 2018/10/9 星期二 21:31:37
你是哪个版本啊
21:32:06
组宣部~李嘉来 2018/10/9 星期二 21:32:06
代码直接运行就行
李✘✘ 2018/10/9 星期二 21:32:27
哦哦
李✘✘ 2018/10/9 星期二 21:32:51
还跟hadoop的版本有关啊
组宣部~李嘉来 2018/10/9 星期二 21:33:06
要倒jar包
组宣部~李嘉来 2018/10/9 星期二 21:33:07
啥的
李✘✘ 2018/10/9 星期二 21:33:28
啊
李✘✘ 2018/10/9 星期二 21:33:31
好麻烦啊
李✘✘ 2018/10/9 星期二 21:33:47
好像都要弄
李✘✘ 2018/10/9 星期二 21:33:56
我每个项目都要弄jar报
李✘✘ 2018/10/9 星期二 21:33:57
包
李✘✘ 2018/10/9 星期二 21:34:00
21:34:32
组宣部~李嘉来 2018/10/9 星期二 21:34:32
好像是、我这就运行不了
李✘✘ 2018/10/9 星期二 21:36:09
那你咋办啊
组宣部~李嘉来 2018/10/9 星期二 21:36:21
不要了
组宣部~李嘉来 2018/10/9 星期二 21:36:25
分不要了
组宣部~李嘉来 2018/10/9 星期二 21:36:32
或者骗他一下
21:39:12
李✘✘ 2018/10/9 星期二 21:39:12
李✘✘ 2018/10/9 星期二 21:39:25
你把季方那个给我发一份可以吗
李✘✘ 2018/10/9 星期二 21:39:28
组宣部~李嘉来 2018/10/9 星期二 21:39:29
我找了一个文本编辑器代码、在单独用一个、上传hdfs文件的代码骗他一下
李✘✘ 2018/10/9 星期二 21:39:34
汗
李✘✘ 2018/10/9 星期二 21:39:38
李✘✘ 2018/10/9 星期二 21:39:46
全是这样骗他
组宣部~李嘉来 2018/10/9 星期二 21:40:12
21:41:53
组宣部~李嘉来 2018/10/9 星期二 21:41:53
你hadoop那个版本嘞
组宣部~李嘉来 2018/10/9 星期二 21:41:58
2.7.几
李✘✘ 2018/10/9 星期二 21:42:11
2.9.1
李✘✘ 2018/10/9 星期二 21:42:24
组宣部~李嘉来 2018/10/9 星期二 21:43:20
21:44:44
李✘✘ 2018/10/9 星期二 21:44:44
好多啊
组宣部~李嘉来 2018/10/9 星期二 21:45:50
别挣扎了
组宣部~李嘉来 2018/10/9 星期二 21:45:51
放弃吧
组宣部~李嘉来 2018/10/9 星期二 21:45:55
傻逼王建民
李✘✘ 2018/10/9 星期二 21:46:03
李✘✘ 2018/10/9 星期二 21:46:09
这个贱人啊
21:53:18
组宣部~李嘉来 2018/10/9 星期二 21:53:18
package com.ibeifeng.hdfs.test.hdfs_demo;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Scanner;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class Client2 {
private static Scanner s = new Scanner( System.in);
public static void main(String[]args) throws Exception{
Configuration conf = new Configuration();
conf.set("fs.defaultFS","hdfs:// bd.zhucheng.com:8020");
conf.set("dfs.replication", "1");
FileSystem fs = FileSystem.get(conf);
int op = 0;
String str = null;
int flag = 1;
while(flag==1) {
System.out.println("输入选项: 1.新建 2.打开 3.编辑");
op = s.nextInt();
switch(op) {
case 1:
System.out.println("输入文件名:");
str = s.next();
if(str.startsWith("/")) {
Path path = new Path(str);
fs.create(path);
}else {
Path path = new Path("/"+str);
fs.create(path);
}
System.out.println("创建成功!");
break;
case 2:
System.out.println("输入文件名:");
str = s.next();
Path path = null;
if(str.startsWith("/"))path = new Path(str);
else path = new Path("/"+str);
FSDataInputStream inputStream = fs.open(path);
BufferedReader d = new BufferedReader(new InputStreamReader(inputStream));
System.out.println("内容为:");
while((str=d.readLine())!=null)System.out.println(str);
d.close();
inputStream.close();
break;
case 3:
System.out.println("输入文件名:");
str = s.next();
Path path3 = null;
if(str.startsWith("/"))path3 = new Path(str);
else path3 = new Path("/"+str);
System.out.println("输入编辑内容:");
str = s.nextLine();
String strt = "";
while(!strt.equals("bye")) {
strt = s.nextLine();
str += ("\n"+strt);
}
str = str.replaceAll("bye","");
int op3 = 2;
System.out.println("\n追加到 1.头 2.尾");
op3 = s.nextInt();
if(op3==1) {
FSDataInputStream inputStream3 = fs.open(path3);
String str3 = null;
try {
str3 = inputStream3.readUTF();
str = str + str3;
}catch(Exception e) {
str3 = "";
str = str +"\n"+ str3;
}
inputStream3.close();
fs.deleteOnExit(path3);
FSDataOutputStream outputStream = fs.create(path3);
outputStream.write(str.getBytes());
outputStream.close();
}else {
FSDataOutputStream outputStream = fs.append(path3);
outputStream.write(str.getBytes());
outputStream.close();
}
break;
case 100:flag = 0;fs.close();s.close();break;
default:break;
}
}
}
}
21:57:32
李✘✘ 2018/10/9 星期二 21:57:32
这是谁的啊
李✘✘ 2018/10/9 星期二 21:57:38
组宣部~李嘉来 2018/10/9 星期二 21:57:48
据说是罗爽的
李✘✘ 2018/10/9 星期二 21:58:12
哦哦
李✘✘ 2018/10/9 星期二 21:58:25
传的够远
21:59:49
组宣部~李嘉来 2018/10/9 星期二 21:59:49
你实验二截图了吗
组宣部~李嘉来 2018/10/9 星期二 22:00:02
我先写实验报告了
李✘✘ 2018/10/9 星期二 22:00:07
嗯嗯
李✘✘ 2018/10/9 星期二 22:00:11
没写完呢