流整理

流的概念和分类

1.按照数据流方向分为输入流,输出流

2.处理单位不同分为字节流和字符流

3.功能不同分为节点流和处理流

字节输入流 inputstream 字节输出流 outputstream

字符输入流 reader      字符输出流writer

4一个重要的类 File

listRoots();

getFreeSpace();

getTotalSpace();

file.exits();

file.isfile();

file.canRead();

file.canWrite();

file.isHidden();

file.canExcute();

file.getAbsolutePath();

file.getParents();

file.length();

file.lastModified();

file.siDirectory();

file.listFiles();返回File[]

file.getpath();

获得根目录磁盘

File[] disks=File.listRoots();

for(int i=0;i<disks.length;i++){

File disk=disks[i];

System.outprint("磁盘的名称是:"+disk+"\t");

long g=1024*1024*1024;

System.outprint("总空间大小是:"+dist.getTotalSpace()/g+"G\t");

System.outprint("剩余空间大小是:"+dist.getFreeSpace()/g+"G\t");

递归循环输出目录下所有文件

/**

 * 使用递归

 * @param files 文件夹下的所有文件集合

 */

public static void openFile(File[]files){

  for(File file : files) {

  System.out.println(file.getPath());

  if((!file.getName().equals("$RECYCLE.BIN"))&&file.isDirectory()){

  openFile(file.listFiles());

  }

  }

}

5.1.字节输入流inputStream

//向输出流中写入一个字节数据,该字节数据为参数b的低8位
void write(int b) throws IOException
//将一个字节类型的数组中的数据写入输出流
void write(byte[] b) throws IOException
//将一个字节类型的数组中的从指定位置(off)开始的
//len个字节写入到输出流
void write(byte[] b, int off, int len)
                      throws IOException
//关闭流释放内存资源
void close() throws IOException 


//将输出流中缓冲的数据全部写出到目的地
void flush() throws IOException

程序

File file = new File("C:/FileTest/a.txt");
InputStream input = new FileInputStream(file);
int i;
//读取一个字节并以整数的形式返回(0~255),
//如果返回-1已到输入流的末尾。
while((i=input.read())!=-1){
System.out.println((char)i);
}
input.close();

byte[] bs = new byte[(int)file.length()];
input.read(bs);
input.close();
String s = new String(bs);
System.out.println(s);
input.close();

outPutStream 字节输出流

//向输出流中写入一个字节数据,该字节数据为参数b的低8位

void write(intb) throwsIOException

//将一个字节类型的数组中的数据写入输出流

void write(byte[] b) throws IOException

//将一个字节类型的数组中的从指定位置(off)开始的

//len个字节写入到输出流

void write(byte[] b, intoff, int len)

                      throws IOException

//关闭流释放内存资源

void close() throws IOException

//将输出流中缓冲的数据全部写出到目的地

void flush() throws IOException

输出中文

String s="包含的字符串";

output.(s.getBytes());

out.flush();

out.close();

Reader

//读取一个字符并以整数的形式返回(0 到 65535),
//如果返回-1已到输入流的末尾。
int read() throws IOException
//读取一系列字符并存储到一个数组buffer,
//返回实际读取的字符数,如果读取前已到输入流的末尾返回-1
int read(char[] cbuf) throws IOException
//读取length个字符
//并存储到一个数组buffer,从off位置开始存,最多读取len
//返回实际读取的字符数,如果读取前以到输入流的末尾返回-1
int read(char[] cbuf, int off, int len)
throws IOException
//关闭流释放内存资源
void close() throws IOException

//文件输入流
File file = new File("C:/FileTest/b.txt");
Reader reader = new FileReader(file);
int i;
while((i=reader.read())!=-1){

System.out.print((char)i);
}
reader.close();


writer

//向输出流中写入一个字符数据,该字节数据为参数b的低16位
void write(int c) throws IOException
//将一个字符类型的数组中的数据写入输出流,
void write(char[] cbuf) throws IOException
//将一个字符类型的数组中的从指定位置(offset)开始的
//length个字符写入到输出流
void write(char[] cbuf, int offset, int length)
          throws IOException
//将一个字符串中的字符写入到输出流
void write(String string) throws IOException
//将一个字符串从offset开始的length个字符写入到输出流
void write(String string, int offset, int length)
          throws IOException
//关闭流释放内存资源
void close() throws IOException 
//将输出流中缓冲的数据全部写出到目的地
void flush() throws IOException

程序

//文件输出流
File file = new File("C:/FileTest/c.txt");
Writer fw = new FileWriter(file);
fw.write("你好");
fw.flush();
fw.close();

COPY文件到另一个


节点流


处理流



使用字符流COPY文件

Filefile = new File("c:/FileTest/duo.txt");

  File dest = newFile("c:/FileTest/dest.txt");

  FileReader fr = new FileReader(file);

  FileWriter fw = new FileWriter(dest);

  System.out.println(new Date());

  int i;

  while((i=fr.read())!=-1){

  fw.write(i);

  }

  System.out.println(new Date());

  fw.flush();

  fw.close();

  fr.close();


内容概要:本文档详细介绍了基于MATLAB实现多目标差分进化(MODE)算法进行无人机三维路径规划的项目实例。项目旨在提升无人机在复杂三维环境中路径规划的精度、实时性、多目标协调处理能力、障碍物避让能力和路径平滑性。通过引入多目标差分进化算法,项目解决了传统路径规划算法在动态环境和多目标优化中的不足,实现了路径长度、飞行安全距离、能耗等多个目标的协调优化。文档涵盖了环境建模、路径编码、多目标优化策略、障碍物检测与避让、路径平滑处理等关键技术模块,并提供了部分MATLAB代码示例。 适合人群:具备一定编程基础,对无人机路径规划和多目标优化算法感兴趣的科研人员、工程师和研究生。 使用场景及目标:①适用于无人机在军事侦察、环境监测、灾害救援、物运输、城市管理等领域的三维路径规划;②通过多目标差分进化算法,优化路径长度、飞行安全距离、能耗等多目标,提升无人机任务执行效率和安全性;③解决动态环境变化、实时路径调整和复杂障碍物避让等问题。 其他说明:项目采用模块化设计,便于集成不同的优化目标和动态环境因素,支持后续算法升级与功能扩展。通过系统实现和仿真实验验证,项目不仅提升了理论研究的实用价值,还为无人机智能自主飞行提供了技术基础。文档提供了详细的代码示例,有助于读者深入理解和实践该项目。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值