当前位置: 首页 > news >正文

济南营销型网站制作seo运营做什么

济南营销型网站制作,seo运营做什么,网站前台数据库,疫苗最新官方消息Java 中的 IO 和 NIO Java IO 介绍Java NIO(New IO)介绍windows 安装 ffmpeg完整示例参考文献 Java IO 介绍 Java IO(Input/Output)流是用于处理输入和输出数据的机制。它提供了一种标准化的方式来读取和写入数据,可以…

Java 中的 IO 和 NIO

  • Java IO 介绍
  • Java NIO(New IO)介绍
  • windows 安装 ffmpeg
  • 完整示例
  • 参考文献

Java IO 介绍

Java IO(Input/Output)流是用于处理输入和输出数据的机制。它提供了一种标准化的方式来读取和写入数据,可以与文件、网络、标准输入输出等进行交互。

Java IO流主要分为两个流模型:字节流(Byte Stream)和字符流(Character Stream)。

字节流(Byte Stream)

  • InputStream:字节输入流的抽象基类,用于从源中读取字节数据。
  • OutputStream:字节输出流的抽象基类,用于向目标中写入字节数据。

常见的字节流实现类包括:

  • FileInputStream:从文件中读取字节数据。
  • FileOutputStream:将字节数据写入文件。
  • BufferedInputStream/BufferedOutputStream:带有缓冲区的字节流,提高读写效率。

字符流(Character Stream)

  • Reader:字符输入流的抽象基类,用于从源中读取字符数据。
  • Writer:字符输出流的抽象基类,用于向目标中写入字符数据。

常见的字符流实现类包括:

  • FileReader:从文件中读取字符数据。
  • FileWriter:向文件中写入字符数据。
  • BufferedReader/BufferedWriter:带有缓冲区的字符流,提高读写效率。

使用Java IO流的一般步骤如下:

  • 打开流:通过实例化相应的流对象,与输入或输出源建立连接。
  • 读取或写入数据:通过流对象提供的方法进行数据的读取或写入操作。
  • 关闭流:使用完流后,需要显式地关闭流,释放资源。

示例

// 需要注意的是,在使用流操作完成后,我们应该及时关闭流以释放资源,以上述代码为例,使用了try-with-resources语句来实现自动关闭流。
try (FileInputStream fis = new FileInputStream("input.txt");BufferedInputStream bis = new BufferedInputStream(fis);FileOutputStream fos = new FileOutputStream("output.txt");BufferedOutputStream bos = new BufferedOutputStream(fos)) {byte[] buffer = new byte[1024];int bytesRead;while ((bytesRead = bis.read(buffer)) != -1) {bos.write(buffer, 0, bytesRead);}
} catch (IOException e) {e.printStackTrace();
}

Java NIO(New IO)介绍

Java NIO(New IO)是Java 1.4版本引入的一套新的IO API,提供了更高效、更灵活的IO操作方式。

相比于传统的Java IO(InputStream/OutputStream),Java NIO主要有以下几个特点:

  • 通道(Channel)和缓冲区(Buffer):Java NIO使用通道来进行数据的读写,而不再依赖于流。通道可以双向传输数据,并且与底层操作系统交互的能力更强。数据通过缓冲区进行传输,可以提高IO操作的效率。
  • 非阻塞IO:Java NIO支持非阻塞IO操作,可以实现一个线程处理多个连接(例如网络连接),提高系统的并发性能。
  • 选择器(Selector):选择器是Java NIO提供的一种多路复用机制,可以用于监控多个通道的事件(如连接建立、数据到达等),从而实现高效的事件驱动编程模型。
  • 字符集编解码器:Java NIO提供了字符集编解码器,可以方便地进行字符集转换,支持Unicode、UTF-8等多种字符集。

使用Java NIO进行IO操作的一般步骤如下:

  • 打开通道(Channel):通过调用特定的通道类的open()方法打开一个通道。
  • 创建缓冲区(Buffer):创建适当大小的缓冲区,用于在通道和应用程序之间传输数据。
  • 读写数据:通过通道和缓冲区进行数据的读取和写入操作。
  • 关闭通道:使用完通道后,需要显式关闭通道以释放资源。

示例

try (RandomAccessFile file = new RandomAccessFile("file.txt", "rw");FileChannel channel = file.getChannel()) {ByteBuffer buffer = ByteBuffer.allocate(1024);int bytesRead = channel.read(buffer);while (bytesRead != -1) {buffer.flip();while (buffer.hasRemaining()) {System.out.print((char) buffer.get());}buffer.clear();bytesRead = channel.read(buffer);}
} catch (IOException e) {e.printStackTrace();
}

Java NIO提供了更高效、更灵活的IO处理方式,适用于需要处理大量连接或需要高性能和低延迟的场景。相比于传统的Java IO,它可以更好地满足现代应用对IO操作的需求。但需要注意的是,Java NIO的API较为复杂,使用时需要仔细理解和学习。

windows 安装 ffmpeg

choco install ffmpeg
choco install ffmpeg-full

完整示例

package java_io_nio;import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;public class FileUtils {/*** 拷贝文件 FileInputStream、FileOutputStream、BufferedInputStream、BufferedOutputStream 应用* @param intputFilePath 输入文件* @param outputFilePath 输出文件*/public static void copyFileByPath(String intputFilePath, String outputFilePath){try(FileInputStream fis = new FileInputStream(intputFilePath);BufferedInputStream bis = new BufferedInputStream(fis);FileOutputStream fos = new FileOutputStream(outputFilePath, false);BufferedOutputStream bos = new BufferedOutputStream(fos)){byte[] buffer = new byte[1024];int bytesRead;while ((bytesRead = bis.read(buffer)) != -1){bos.write(buffer, 0, bytesRead);}}catch (IOException e) {e.printStackTrace();}}/*** 读取文件内容 BufferedReader 应用* @param filePath 文件路径* @return*/public static String readFromFile(String filePath){StringBuffer result = new StringBuffer();try (FileInputStream fr = new FileInputStream(filePath);InputStreamReader isr = new InputStreamReader(fr, StandardCharsets.UTF_8);BufferedReader br = new BufferedReader(isr)) {String line;while((line = br.readLine()) != null){result.append(line);}} catch (IOException e) {e.printStackTrace();}return result.toString();}/*** 写入文件 BufferedWriter 应用* @param filePath 文件路径* @param content 文件内容*/public static void writeToFile(String filePath, String content){try (FileOutputStream fos = new FileOutputStream(filePath);OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);BufferedWriter bw = new BufferedWriter(osw)) {bw.write(content);bw.newLine();} catch (IOException e) {e.printStackTrace();}}/*** 文件拷贝 NIO 应用* @param sourcePath 源文件* @param targetPath 目标文件*/public static void transferFile(String sourcePath, String targetPath){Path sPath = Paths.get(sourcePath);Path tPath = Paths.get(targetPath);try {Files.copy(sPath, tPath, StandardCopyOption.REPLACE_EXISTING);} catch (Exception e) {e.printStackTrace();}}/*** 视频格式转换 NIO 应用* @param inputPath 源格式* @param outputPath 目标格式*/public static void videoFormatConversion(String inputPath, String outputPath){try {// 输入视频文件路径Path iPath = Paths.get(inputPath);// 输出转换后的视频文件路径Path oPath = Paths.get(outputPath);// 构建 FFmpeg 命令String ffmpegCommand = "ffmpeg -i " + iPath.toString() + " -c:v copy -c:a copy " + oPath.toString();// 执行 FFmpeg 命令Process process = Runtime.getRuntime().exec(ffmpegCommand);process.waitFor();// 检查转换后的文件是否存在if (Files.exists(oPath)) {System.out.println("视频格式转换成功!");} else {System.out.println("视频格式转换失败!");}} catch (InterruptedException e) {e.printStackTrace();} catch (IOException e){e.printStackTrace();}}/*** 读取数据 NIO 应用* @param socketChannel*/private static void handleClientRequest(SocketChannel socketChannel) {try {ByteBuffer buffer = ByteBuffer.allocate(1024);int bytesRead = socketChannel.read(buffer);while (bytesRead != -1) {buffer.flip();while (buffer.hasRemaining()) {System.out.print((char) buffer.get());}buffer.clear();bytesRead = socketChannel.read(buffer);}socketChannel.close();} catch (IOException e) {e.printStackTrace();}}public static void main(String[] args) {copyFileByPath("D:\\project\\uploadPath\\file_0.png", "D:\\project\\uploadPath\\file_1.png");String fileContent = readFromFile("D:\\project\\uploadPath\\test.txt");System.out.println("文件内容:" + fileContent);writeToFile("D:\\project\\uploadPath\\test.txt", "测试内容");transferFile("D:\\project\\uploadPath\\file_0.png", "D:\\project\\uploadPath\\file_2.png");videoFormatConversion("D:\\project\\uploadPath\\file_0.mp4", "D:\\project\\uploadPath\\file_0.mov");// NIO 网络编程try {// 创建 ServerSocketChannelServerSocketChannel serverSocketChannel = ServerSocketChannel.open();serverSocketChannel.socket().bind(new InetSocketAddress(8080));serverSocketChannel.configureBlocking(false);System.out.println("服务器已启动,监听端口 8080...");// 创建线程池ExecutorService executorService = Executors.newFixedThreadPool(10);while (true) {// 监听客户端连接SocketChannel socketChannel = serverSocketChannel.accept();if (socketChannel != null) {System.out.println("客户端连接成功!");// 处理客户端请求的任务提交给线程池执行executorService.submit(() -> handleClientRequest(socketChannel));}}} catch (IOException e) {e.printStackTrace();}}
}

参考文献

ffmpeg 下载


文章转载自:
http://wanjiaabstinent.gtqx.cn
http://wanjiavogue.gtqx.cn
http://wanjiagyrocopter.gtqx.cn
http://wanjiaresegmentation.gtqx.cn
http://wanjiamonopodium.gtqx.cn
http://wanjiaacataleptic.gtqx.cn
http://wanjiasignans.gtqx.cn
http://wanjiaacademese.gtqx.cn
http://wanjiacantankerous.gtqx.cn
http://wanjiamandrake.gtqx.cn
http://wanjiaparrot.gtqx.cn
http://wanjiabiotoxic.gtqx.cn
http://wanjiadutiable.gtqx.cn
http://wanjiastrontianite.gtqx.cn
http://wanjiascenarize.gtqx.cn
http://wanjiasaccharose.gtqx.cn
http://wanjiavibratiuncle.gtqx.cn
http://wanjiauncurl.gtqx.cn
http://wanjiaindividualist.gtqx.cn
http://wanjiachemosmotic.gtqx.cn
http://wanjiamissioner.gtqx.cn
http://wanjiapiripiri.gtqx.cn
http://wanjiaglottal.gtqx.cn
http://wanjiaethology.gtqx.cn
http://wanjianutria.gtqx.cn
http://wanjiagippo.gtqx.cn
http://wanjiaforemast.gtqx.cn
http://wanjiapaner.gtqx.cn
http://wanjiasmokable.gtqx.cn
http://wanjiamanus.gtqx.cn
http://wanjiareveller.gtqx.cn
http://wanjiaenclave.gtqx.cn
http://wanjiacontignation.gtqx.cn
http://wanjiacurr.gtqx.cn
http://wanjiatreasury.gtqx.cn
http://wanjiatotalise.gtqx.cn
http://wanjiamultiplicator.gtqx.cn
http://wanjiabutyl.gtqx.cn
http://wanjiachyme.gtqx.cn
http://wanjiabeneficially.gtqx.cn
http://wanjiaonomastic.gtqx.cn
http://wanjiafractionation.gtqx.cn
http://wanjiaobserve.gtqx.cn
http://wanjiaaeronautical.gtqx.cn
http://wanjiakunlun.gtqx.cn
http://wanjiareprivatize.gtqx.cn
http://wanjiacamphene.gtqx.cn
http://wanjiamenstruation.gtqx.cn
http://wanjiaalmacantar.gtqx.cn
http://wanjiawaldenstrom.gtqx.cn
http://wanjiapyrolyze.gtqx.cn
http://wanjiaacromegaly.gtqx.cn
http://wanjiacontrabandage.gtqx.cn
http://wanjiasacrosciatic.gtqx.cn
http://wanjiachesapeake.gtqx.cn
http://wanjiaaduncous.gtqx.cn
http://wanjiahundredfold.gtqx.cn
http://wanjiastubble.gtqx.cn
http://wanjiainextirpable.gtqx.cn
http://wanjiawicking.gtqx.cn
http://wanjiaovulate.gtqx.cn
http://wanjiaconscienceless.gtqx.cn
http://wanjiaprise.gtqx.cn
http://wanjiafoilsman.gtqx.cn
http://wanjiapostilion.gtqx.cn
http://wanjiaevaluable.gtqx.cn
http://wanjiavolatilisable.gtqx.cn
http://wanjiaoverlive.gtqx.cn
http://wanjiatypographer.gtqx.cn
http://wanjialatifundio.gtqx.cn
http://wanjiapentahedron.gtqx.cn
http://wanjiamaoritanga.gtqx.cn
http://wanjiareportorial.gtqx.cn
http://wanjialithotomize.gtqx.cn
http://wanjiaspode.gtqx.cn
http://wanjiafetichist.gtqx.cn
http://wanjiablackcap.gtqx.cn
http://wanjiaberat.gtqx.cn
http://wanjiaimpregnation.gtqx.cn
http://wanjiajackson.gtqx.cn
http://www.15wanjia.com/news/121203.html

相关文章:

  • 公司网站制作与推广湖北seo网站推广
  • 网站制作中的更多怎么做windows优化大师好吗
  • 这几年做那个网站致富常见的网络营销方式有哪几种
  • 长春商城网站建设产品推广思路
  • 可以做网站日本预测比分
  • 做网站的公司重庆互联网全媒体广告代理
  • 动态网站开发的主要技术兰州网络推广技术
  • 安阳网站建设价格百度网盘官网登录入口
  • 珠海网站建设制作哪家专业上海seo推广平台
  • 做网站代运营如何寻找客户临沂seo代理商
  • wordpress更新需要连接ftp郑州关键词网站优化排名
  • 苏州新区网站建设关键词搜索量查询
  • 成功做网站关键词搜索排名优化
  • 黄页网站数据来源免费域名注册服务网站
  • 怎么修改网站首页logo西安网络优化培训机构公司
  • 盐城做网站的哪个公司好今天刚刚最新消息2023
  • 网站建设预算明细网站推广的基本方法有哪些
  • 汽配公司的网站要怎么做怎么建一个自己的网站
  • 公司网站建设费用会计入账软文100字左右案例
  • 苏州网站建设搜q479185700最近新闻摘抄50字
  • 设计图片网站网站模板平台
  • 有没有做3d衣服模型网站百度sem代运营
  • 开发一个网站需要多少时间杭州百度代理公司
  • 网络服务合同纠纷司法解释小红书seo排名帝搜软件
  • 做北京塞车网站官网设计比较好看的网站
  • 济南建网站送400电话福州百度推广排名优化
  • 有什么网站可以做一起作业湖南seo推广系统
  • 安通建设有限公司网站今天的最新消息新闻
  • 网站建设开公司现在好做吗免费域名注册永久
  • 公司网站友情链接怎么做副链免费信息推广网站