- dir显示当前工作目录下的子目录和文件
- more 每次显示一个输出屏幕
- dir | more 以每次显示一个输出屏幕的方式显示当前工作目录下的子目录和文件
这里的 | 是就是管道,将第一个命令的输出作为输入,用第二个命令去处理。
- 管道是进程间通信的方式之一,每一条命令都是一个程序
- 命令的与发紧凑并且简单
- 使用管道,将多个命令串连到一起,有时候可以完成命令单独执行不方便或者不能完成的复杂任务
- 从管道输出的标准错误会混合到一起
将几个命令通过管道符组合在一起就形成了管道。通常,通过这种方式使用的命令就被称为过滤器。过滤器会获取输入,通过某种方式修改其内容,然后将其输出。
- dir命令
C:UsersLiuhd>dir 驱动器 C 中的卷是 Windows-SSD 卷的序列号是 4009-8282 C:UsersLiuhd 的目录 2021/10/10 13:44. 2021/08/16 13:37 .. 2021/10/06 22:31 .android 2021/09/25 11:32 340 .bash_history 2021/04/12 20:51 .cache 2021/09/24 17:03 .config 2021/04/12 20:51 .eclipse 2021/10/01 12:08 16 .emulator_console_auth_token 2021/09/24 17:37 81 .gitconfig 2021/10/01 11:40 .gradle 2021/09/24 17:03 .halo 2021/09/29 16:10 .jdks 2021/04/06 11:08 1,907 .labelmerc 2021/09/29 16:02 .m2 2021/04/06 11:08 .matplotlib 2021/10/10 13:44 .mume 2021/04/06 11:07 12 .python_history 2021/03/29 20:59 .ssh 2021/09/27 20:49 3,362 .viminfo 2021/03/23 20:31 .vscode 2021/03/23 16:46 3D Objects 2021/04/06 11:02 anaconda3 2021/10/01 11:24 AndroidProject 2021/09/02 10:35 CLionProjects 2021/08/16 17:40 Contacts 2021/09/03 22:43 300 d4ac4633ebd6440fa397b84f1bc94a3c.7z 2021/10/11 12:22 Desktop 2021/10/06 16:51 documents 2021/10/10 13:36 Downloads 2021/04/12 20:51 eclipse-workspace 2021/08/16 17:40 Favorites 2021/10/06 17:05 IdeaProjects 2021/08/29 20:19 0 import_sys.SQL 2021/09/03 22:09 66 inittk.ini 2021/09/03 22:09 41 inst.ini 2021/08/16 17:40 links 2021/08/16 17:40 Music 2021/09/03 22:09 Nox_share 2021/09/03 22:09 45 nuuid.ini 2021/10/11 14:01 oneDrive 2021/08/29 18:09 Oracle 2021/09/05 19:41 Pictures 2021/04/26 13:24 PotPlayer 2021/08/16 17:40 Saved Games 2021/08/16 17:40 Searches 2021/03/23 17:06 UIDowner 2021/09/03 22:09 53 useruid.ini 2021/08/16 17:40 Videos 2021/09/03 22:08 vmlogs 12 个文件 6,223 字节 37 个目录 119,086,456,832 可用字节
- dir|more命令
C:UsersLiuhd 的目录 2021/10/10 13:442.使用Java的管道流类实现管道-过滤体系结构,完成客户端发送一段文字,接收端进行接收,利用线程实现这一功能。. 2021/08/16 13:37 .. 2021/10/06 22:31 .android 2021/09/25 11:32 340 .bash_history 2021/04/12 20:51 .cache 2021/09/24 17:03 .config 2021/04/12 20:51 .eclipse 2021/10/01 12:08 16 .emulator_console_auth_token 2021/09/24 17:37 81 .gitconfig 2021/10/01 11:40 .gradle 2021/09/24 17:03 .halo 2021/09/29 16:10 .jdks 2021/04/06 11:08 1,907 .labelmerc 2021/09/29 16:02 .m2 2021/04/06 11:08 .matplotlib 2021/10/10 13:44 .mume 2021/04/06 11:07 12 .python_history 2021/03/29 20:59 .ssh 2021/09/27 20:49 3,362 .viminfo 2021/03/23 20:31 .vscode 2021/03/23 16:46 3D Objects 2021/04/06 11:02 anaconda3 2021/10/01 11:24 AndroidProject 2021/09/02 10:35 CLionProjects 2021/08/16 17:40 Contacts 2021/09/03 22:43 300 d4ac4633ebd6440fa397b84f1bc94a3c.7z 2021/10/11 12:22 Desktop 2021/10/06 16:51 documents 2021/10/10 13:36 Downloads 2021/04/12 20:51 eclipse-workspace 2021/08/16 17:40 Favorites 2021/10/06 17:05 IdeaProjects 2021/08/29 20:19 0 import_sys.SQL 2021/09/03 22:09 66 inittk.ini 2021/09/03 22:09 41 inst.ini 2021/08/16 17:40 links 2021/08/16 17:40 Music 2021/09/03 22:09 Nox_share 2021/09/03 22:09 45 nuuid.ini 2021/10/11 14:01 oneDrive 2021/08/29 18:09 Oracle 2021/09/05 19:41 Pictures 2021/04/26 13:24 PotPlayer -- More --
java的管道输入与输出实际上使用的是一个循环缓冲数组来实现,这个数组默认大小为1024字节。输入流PipedInputStream从这个循环缓冲数组中读数据,输出流PipedOutputStream往这个循环缓冲数组中写入数据。当这个缓冲数组已满的时候,输出流PipedOutputStream所在的线程将阻塞;当这个缓冲数组首次为空的时候,输入流PipedInputStream所在的线程将阻塞。但是在实际用起来的时候,却会发现并不是那么好用。
pipedInputStream.connect(pipedOutputStream)或者pipedOutputStream.connect(pipedInputStream)效果是一样的
只能选择其中的一个,不能两个connect同时调用
在一个线程里使用PipedInpuStream和PipedOutputStream会造成死锁,第二次尝试通过管道输出流写数据的时候阻塞,同时也无法从管道输入流读取数据,感兴趣的同学可以点进这两个类中查看read()和write()这两个方法的源码,这两个都是同步方法。
所以我设计了一个发送端class Sender和一个接收端class Receiver作为管道的两端,在主线程中进行数据的发送,在另一个接收线程中进行数据的接收
这样就可以避免线程,这里要特别注意发送和接收的同步关系
public class PipedDemo{
public static void main(String[] args) {
Receiver receiver = new Receiver();
Sender sender = new Sender(receiver);
sender.send();
new Thread(receiver).start();
}
}
class Sender{
private PipedOutputStream pipedOutputStream = new PipedOutputStream();
public Sender(Receiver receiver) {
try {
pipedOutputStream.connect(receiver.getPipedInputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
public void send() {
try {
String str = "你好!我是管道来的!";
pipedOutputStream.write(str.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}
class Receiver implements Runnable{
private PipedInputStream pipedInputStream = new PipedInputStream();
public PipedInputStream getPipedInputStream() {
return pipedInputStream;
}
@Override
public void run() {
int n = 0;
byte[] bytes = new byte[1024];
try {
int l = pipedInputStream.read(bytes);
System.out.println(new String(bytes,0,l));
} catch (IOException e) {
e.printStackTrace();
}
}
}
(3)在二维空间中存在一个图形类,以这个图形类为基础定义了一些图形:矩形、正方形、圆形、椭圆。使用面向对象的思想进行编程,并计算每个图形的面积。
话不多说看图吧
- Calculable.java
public interface Calculable {
double CalculateArea();
}
- Shape.java
public abstract class Shape implements Calculable{
protected double area; // 面积
}
- Rectangle.java
public class Rectangle extends Shape{
private int length;
private int width;
@Override
public double CalculateArea() {
area = length * width;
return area;
}
}
- Square.java
public class Square extends Shape{
private int side;
@Override
public double CalculateArea() {
area = side * side;
return side;
}
}
- Circular.java
public class Circular extends Shape{
private int radius;
@Override
public double CalculateArea() {
area = Math.PI * radius * radius;
return area;
}
}
- Ellipse.java
public class Ellipse extends Shape{
private int majorAxis; //长轴
private int minorAxis; //短轴
@Override
public double CalculateArea() {
area = Math.PI * majorAxis * minorAxis;
return area;
}
}



