Java中流(Stream)、文件(File)和IO示例詳解
一、Java 流(Stream)、文件(File)和IO概念和關(guān)系
Java 中的流(Stream)、文件(File)和 IO 之間是緊密關(guān)聯(lián)但又各有側(cè)重的概念,它們共同構(gòu)成了 Java 輸入輸出系統(tǒng)的核心??梢杂?quot;工具-對象-操作"的關(guān)系來理解:
IO 是總稱
IO(Input/Output,輸入/輸出)是所有數(shù)據(jù)傳輸操作的統(tǒng)稱,涵蓋了程序與外部設(shè)備(文件、網(wǎng)絡(luò)、鍵盤等)之間的數(shù)據(jù)交換。
流(Stream)和文件(File)都是實現(xiàn) IO 操作的具體方式或操作對象。File 是操作的實體
java.io.File類代表文件系統(tǒng)中的一個文件或目錄,是 IO 操作的具體對象。
但它本身不能直接讀寫數(shù)據(jù),只能描述文件的屬性(如路徑、大小、是否存在等),并提供創(chuàng)建、刪除等文件管理功能。Stream 是操作的工具
流(Stream)是連接程序與外部數(shù)據(jù)源(包括 File)的數(shù)據(jù)傳輸通道,是實現(xiàn) IO 操作的核心工具。
當(dāng)需要讀寫 File 中的內(nèi)容時,必須通過流來實現(xiàn):- 讀文件:用輸入流(如
FileInputStream)從 File 中讀取數(shù)據(jù)到程序 - 寫文件:用輸出流(如
FileOutputStream)從程序?qū)懭霐?shù)據(jù)到 File
- 讀文件:用輸入流(如
三者協(xié)作關(guān)系
一個典型的文件 IO 操作流程是:
創(chuàng)建 File 對象(指定要操作的文件) → 通過流連接 File(如 new FileInputStream(file)) → 通過流進(jìn)行 IO 操作(讀/寫數(shù)據(jù))
二、讀寫文件
2.1 操作文件時涉及的字符流和字節(jié)流的概念介紹:
字節(jié)流
基本概念:字節(jié)流是以字節(jié)(8位二進(jìn)制數(shù)據(jù))作為基本處理單位的流,它能對各種類型的文件進(jìn)行讀寫操作,因為計算機(jī)中所有的數(shù)據(jù)在底層都是以字節(jié)形式存儲和傳輸?shù)?。字?jié)流可以直接操作二進(jìn)制數(shù)據(jù),無論是文本文件還是非文本文件(如圖像、音頻、視頻等)都能處理。
字節(jié)輸入流(InputStream):
用于從文件等數(shù)據(jù)源讀取字節(jié)數(shù)據(jù)到程序中。它是字節(jié)流輸入操作的抽象基類,提供了如read()等基礎(chǔ)方法用于讀取字節(jié)數(shù)據(jù)。字節(jié)輸出流(OutputStream):
負(fù)責(zé)將程序中的字節(jié)數(shù)據(jù)寫入到文件等目標(biāo)數(shù)據(jù)源中。它是字節(jié)流輸出操作的抽象基類,提供了write()等方法用于寫入字節(jié)數(shù)據(jù)。
字符流
基本概念:字符流以字符(一般是16位的Unicode編碼字符)為基本處理單位,更側(cè)重于處理文本文件,它在讀寫文本時會按照字符編碼規(guī)范進(jìn)行轉(zhuǎn)換,能更好地保證文本內(nèi)容的正確讀寫,還能方便地按行等文本特性進(jìn)行操作。
字符輸入流(Reader):
用于從文件等數(shù)據(jù)源讀取字符數(shù)據(jù)到程序里,是字符流輸入操作的抽象基類,提供了read()等方法來獲取字符數(shù)據(jù)。字符輸出流(Writer):
主要用于將程序中的字符數(shù)據(jù)寫入到文件等目標(biāo)數(shù)據(jù)源中,是字符流輸出操作的抽象基類,具備write()等方法來輸出字符數(shù)據(jù)。
字節(jié)流、字符流常用關(guān)系圖

2.2 字節(jié)流常用方法
字節(jié)流常用于處理二進(jìn)制數(shù)據(jù),例如文件、圖像、時頻。
| 類名 | 類型 | 描述 |
|---|---|---|
| InputStream | 抽象類(輸入流) | 所有字節(jié)輸入流的超類,處理字節(jié)的輸入操作 |
| OutputStream | 抽象類(輸出流) | 所有字節(jié)輸出流的超類,處理字節(jié)的輸出操作 |
| FileInputStream | 輸入流 | 從文件中讀取字節(jié)數(shù)據(jù) |
| FileOutputStream | 輸出流 | 將字節(jié)數(shù)據(jù)寫入文件 |
| BufferedInputStream | 輸入流 | 為字節(jié)輸入流提供緩沖功能,提高讀取效率 |
| BufferedOutputStream | 輸出流 | 為字節(jié)輸出流提供緩沖功能,提高寫入效率 |
| ByteArrayInputStream | 輸入流 | 將內(nèi)存中的字節(jié)數(shù)組作為輸入源 |
| ByteArrayOutputStream | 輸出流 | 將數(shù)據(jù)寫入到內(nèi)存中的字節(jié)數(shù)組 |
| DataInputStream | 輸入流 | 允許從輸入流中讀取Java原生數(shù)據(jù)類型(如int、float、boolean等) |
| DataOutputStream | 輸出流 | 允許向輸出流中寫入Java原生數(shù)據(jù)類型 |
| ObjectInputStream | 輸入流 | 從輸入流中讀取序列化對象 |
| ObjectOutputStream | 輸出流 | 將對象序列化并寫入輸出流中 |
| PipedInputStream | 輸入流 | 用于在管道中讀取字節(jié)數(shù)據(jù),通常與PipedOutputStream配合使用 |
| PipedOutputStream | 輸出流 | 用于在管道中寫入字節(jié)數(shù)據(jù),通常與PipedInputStream配合使用 |
| FilterInputStream | 輸入流 | 字節(jié)輸入流的包裝類,用于對其他輸入流進(jìn)行過濾處理 |
| FilterOutputStream | 輸出流 | 字節(jié)輸出流的包裝類,用于對其他輸出流進(jìn)行過濾處理 |
| SequenceInputStream | 輸入流 | 將多個輸入流串聯(lián)為一個輸入流進(jìn)行處理 |
以下是基于表格中各類字節(jié)流的讀寫文件示例,涵蓋不同場景的文件操作:
1. FileInputStream/FileOutputStream(基礎(chǔ)文件讀寫)
FileInputStream 和 FileOutputStream 是 Java IO 中用于直接操作文件的字節(jié)流,專門負(fù)責(zé)從文件讀取字節(jié)數(shù)據(jù)和向文件寫入字節(jié)數(shù)據(jù),是處理文件字節(jié)流的基礎(chǔ)類。
import java.io.*;
public class Main {
public static void main(String[] args) {
// 寫入文件
try {
FileOutputStream fileOutputStream =new FileOutputStream("file.txt");
String data="Hello byteStream!";
fileOutputStream.write(data.getBytes());
fileOutputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
FileInputStream fileInputStream =new FileInputStream("file.txt");
int c;
while((c=fileInputStream.read())!=-1){
System.out.print((char)c);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

2. BufferedInputStream/BufferedOutputStream(緩沖流高效讀寫)
BufferedInputStream 和 BufferedOutputStream 是 Java IO 中提供緩沖功能的過濾流,它們通過在內(nèi)存中維護(hù)緩沖區(qū)來減少物理 I/O 操作次數(shù),從而顯著提升讀寫效率。
import java.io.*;
public class Main {
public static void main(String[] args) {
// 寫入文件
try {
BufferedOutputStream bufferedOutputStream =new BufferedOutputStream(new FileOutputStream("file.txt"));
String data="Hello byteStream!";
bufferedOutputStream.write(data.getBytes());
bufferedOutputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
BufferedInputStream bufferedInputStream =new BufferedInputStream(new FileInputStream("file.txt"));
int c;
while((c=bufferedInputStream.read())!=-1){
System.out.print((char)c);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
3. DataInputStream/DataOutputStream(讀寫基本數(shù)據(jù)類型)
DataInputStream 和 DataOutputStream 是 Java IO 中用于讀寫基本數(shù)據(jù)類型的過濾流,它們可以直接操作 Java 原生數(shù)據(jù)類型(如 int、double、boolean 等),無需手動處理字節(jié)轉(zhuǎn)換,簡化了基本類型數(shù)據(jù)的讀寫操作。
import java.io.*;
public class Main {
public static void main(String[] args) {
// 寫入文件
try {
DataOutputStream bufferedOutputStream =new DataOutputStream(new FileOutputStream("file.bat"));
bufferedOutputStream.writeInt(100); // 寫入整數(shù)
bufferedOutputStream.writeDouble(3.14); // 寫入雙精度浮點(diǎn)數(shù)
bufferedOutputStream.writeUTF("Hello byteStream!");
bufferedOutputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
DataInputStream bufferedInputStream =new DataInputStream(new FileInputStream("file.bat"));
System.out.println(bufferedInputStream.readInt());
System.out.println(bufferedInputStream.readDouble());
System.out.println(bufferedInputStream.readUTF());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

4. ObjectInputStream/ObjectOutputStream(對象序列化)
ObjectInputStream 和 ObjectOutputStream 是 Java 中用于對象序列化與反序列化的字節(jié)流,主要功能是將內(nèi)存中的 Java 對象轉(zhuǎn)換為字節(jié)序列(序列化)并寫入流中,或從流中讀取字節(jié)序列并恢復(fù)為 Java 對象(反序列化)。
import java.io.*;
// 需實現(xiàn)Serializable接口才能被序列化
class User implements Serializable {
private String name;
private int age;
public User(String name, int age) {
this.name = name;
this.age = age;
}
@Override
public String toString() {
return "User{name='" + name + "', age=" + age + "}";
}
}
public class Main {
public static void main(String[] args) {
// 序列化對象寫入文件
try {
ObjectOutputStream objectOutputStream =new ObjectOutputStream(new FileOutputStream("file.obj"));
User user=new User("Alice", 18);
objectOutputStream.writeObject(user);
objectOutputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
ObjectInputStream objectInputStream=new ObjectInputStream(new FileInputStream("file.obj"));
User user=(User) objectInputStream.readObject();
System.out.println(user);
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}

5.ByteArrayOutputStream(內(nèi)存字節(jié)數(shù)組讀寫)
它可以將數(shù)據(jù)寫入內(nèi)存中的字節(jié)數(shù)組緩沖區(qū)。創(chuàng)建后可以用來收集和操作字節(jié)數(shù)據(jù),常用于臨時存儲或處理二進(jìn)制數(shù)據(jù)。
public class Main {
public static void main(String[] args) {
ByteArrayOutputStream byteArrayOutputStream =new ByteArrayOutputStream();
byte [] bytes = new byte[1024];
try {
bytes[0]=(byte) 'H';
bytes[1]=(byte) 'e';
bytes[2]=(byte) 'l';
bytes[3]=(byte) 'l';
bytes[4]=(byte) 'o';
byteArrayOutputStream.write(bytes,0,5);
byteArrayOutputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
byte [] bytes1 = new byte[1024];
int c;
try{
while ((c=byteArrayInputStream.read(bytes1))!=-1){
System.out.println(new String(bytes1, 0, c));
}
}catch (IOException e){
throw new RuntimeException(e);
}
}
}

6. SequenceInputStream(合并多個輸入流)
import java.io.*;
public class Main {
public static void main(String[] args) {
try {
SequenceInputStream sequenceInputStream =new SequenceInputStream(new FileInputStream("file.txt"),new FileInputStream("test.txt"));
int c;
while((c=sequenceInputStream.read())!=-1){
System.out.print((char)c);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
7. FilterInputStream/FilterOutStream
FilterInputStream 和 FilterOutputStream 是 Java IO 中的過濾流基類,屬于裝飾器模式(Decorator Pattern)的典型實現(xiàn),用于對現(xiàn)有流進(jìn)行功能擴(kuò)展或增強(qiáng)。
import java.io.FilterInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
// 自定義過濾輸入流:轉(zhuǎn)換為大寫
class UpperCaseInputStream extends FilterInputStream {
/**
* Creates a <code>FilterInputStream</code>
* by assigning the argument <code>in</code>
* to the field <code>this.in</code> so as
* to remember it for later use.
*
* @param in the underlying input stream, or <code>null</code> if
* this instance is to be created without an underlying stream.
*/
protected UpperCaseInputStream(InputStream in) {
super(in);
}
@Override
public int read(byte [] b,int off,int len ) throws IOException {
int result = super.read(b, off, len);//讀取的字節(jié)數(shù)
if(result!=-1){
for(int i=off;i<off+result;i++){
b[i]= (byte) Character.toUpperCase((char)b[i]);
}
}
return result;
}
}
public class Main {
public static void main(String[] args) {
try {
UpperCaseInputStream
upperCaseInputStream =new UpperCaseInputStream(new FileInputStream("file.txt"));
int c;
byte [] bytes=new byte[1024];
while((c=upperCaseInputStream.read(bytes))!=-1){
System.out.print(new String(bytes,0,c));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

8.pipedOutputStream/pipedInputStream
PipedOutputStream 和 PipedInputStream 是 Java 中用于線程間通信的管道流,二者必須配合使用,形成 “生產(chǎn)者 - 消費(fèi)者” 模式的數(shù)據(jù)傳輸通道。
public class Main {
public static void main(String[] args) {
PipedOutputStream pipedOutputStream =new PipedOutputStream();
PipedInputStream pipedInputStream;
try {
pipedInputStream =new PipedInputStream(pipedOutputStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
new Thread(new Runnable() {
@Override
public void run() {
try {
pipedOutputStream.write("Hello byteStream!".getBytes());
pipedOutputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}).start();
new Thread(new Runnable(){
@Override
public void run() {
try {
int c;
while((c=pipedInputStream.read())!=-1){
System.out.print((char)c);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}).start();
}
}
2.3 字符流常用方法
字符流常用于處理文本數(shù)據(jù)。
| 類名 | 類型 | 描述 |
|---|---|---|
| Reader | 抽象類(輸入流) | 所有字符輸入流的超類,處理字符的輸入操作 |
| Writer | 抽象類(輸出流) | 所有字符輸出流的超類,處理字符的輸出操作 |
| FileReader | 輸入流 | 從文件中讀取字符數(shù)據(jù) |
| FileWriter | 輸出流 | 將字符數(shù)據(jù)寫入文件 |
| BufferedReader | 輸入流 | 為字符輸入流提供緩沖功能,支持按行讀取,提高讀取效率 |
| BufferedWriter | 輸出流 | 為字符輸出流提供緩沖功能,支持按行寫入,提高寫入效率 |
| CharArrayReader | 輸入流 | 將字符數(shù)組作為輸入源 |
| CharArrayWriter | 輸出流 | 將數(shù)據(jù)寫入到字符數(shù)組 |
| StringReader | 輸入流 | 將字符串作為輸入源 |
| StringWriter | 輸出流 | 將數(shù)據(jù)寫入到字符串緩沖區(qū) |
| PrintWriter | 輸出流 | 便捷的字符輸出流,支持自動刷新和格式化輸出 |
| PipedReader | 輸入流 | 用于在管道中讀取字符數(shù)據(jù),通常與 PipedWriter 配合使用 |
| PipedWriter | 輸出流 | 用于在管道中寫入字符數(shù)據(jù),通常與 PipedReader 配合使用 |
| LineNumberReader | 輸入流 | 帶行號的緩沖字符輸入流,允許跟蹤讀取的行號 |
| PushbackReader | 輸入流 | 允許在讀取字符后將字符推回流中,以便再次讀取 |
以下是字符流各類的讀寫文件示例,每個示例均包含寫入和讀取操作:
1. FileReader/FileWriter(文件字符讀寫)
import java.io.*;
public class Main {
public static void main(String[] args) {
// 寫入文本到文件
try (FileWriter writer = new FileWriter("test.txt")) {
writer.write("Hello, FileReader/FileWriter!\n");
writer.write("這是一行行中文文本");
} catch (IOException e) {
e.printStackTrace();
}
// 從文件讀取文本
try (FileReader reader = new FileReader("test.txt")) {
char[] buffer = new char[1024];
int len;
while ((len = reader.read(buffer)) != -1) {
System.out.print(new String(buffer, 0, len));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

2. BufferedReader/BufferedWriter(緩沖字符流)
public class Main {
public static void main(String[] args) {
// 按行寫入文本(指定UTF-8編碼)
try (BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream("buffered.txt"), StandardCharsets.UTF_8))) {
writer.write("第一行內(nèi)容");
writer.newLine(); // 跨平臺換行
writer.write("第二行內(nèi)容");
} catch (IOException e) {
e.printStackTrace();
}
// 按行讀取文本
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(new FileInputStream("buffered.txt"), StandardCharsets.UTF_8))) {
String line;
while ((line = reader.readLine()) != null) { // 按行讀取
System.out.println("讀取到:" + line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
3. CharArrayReader/CharArrayWriter(字符數(shù)組流)
CharArrayReader 和 CharArrayWriter 是 Java 中以字符數(shù)組為操作對象的字符流,所有操作均在內(nèi)存中基于字符數(shù)組完成,無需依賴外部存儲。
import java.io.*;
public class CharArrayReadWriteExample {
public static void main(String[] args) {
// CharArrayWriter先寫入字符數(shù)組(內(nèi)存中)
CharArrayWriter caw = new CharArrayWriter();
try {
caw.write("先寫入內(nèi)存字符數(shù)組,再轉(zhuǎn)存到文件");
char[] charData = caw.toCharArray(); // 獲取字符數(shù)組
// 寫入文件
try (FileWriter fw = new FileWriter("charArray.txt")) {
fw.write(charData);
}
// CharArrayReader從字符數(shù)組讀取
CharArrayReader car = new CharArrayReader(charData);
char[] buffer = new char[1024];
int len;
System.out.println("CharArrayReader讀取內(nèi)容:");
while ((len = car.read(buffer)) != -1) {
System.out.print(new String(buffer, 0, len));
}
car.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
caw.close();
}
}
}
4. StringReader/StringWriter(字符串流)
StringReader 和 StringWriter 是 Java 中操作內(nèi)存字符串的字符流,無需依賴外部文件,所有操作均在內(nèi)存中完成。
import java.io.*;
public class StringReadWriteExample {
public static void main(String[] args) {
// StringWriter寫入字符串緩沖區(qū)
StringWriter sw = new StringWriter();
try {
sw.write("字符串流操作示例\n");
sw.write("數(shù)據(jù)保存在StringBuffer中");
String data = sw.toString(); // 獲取字符串
// 寫入文件
try (FileWriter fw = new FileWriter("string.txt")) {
fw.write(data);
}
// StringReader從字符串讀取
StringReader sr = new StringReader(data);
char[] buffer = new char[1024];
int len;
System.out.println("StringReader讀取內(nèi)容:");
while ((len = sr.read(buffer)) != -1) {
System.out.print(new String(buffer, 0, len));
}
sr.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
sw.close();
}
}
}
5. PrintWriter(格式化字符輸出流)
PrintWriter 是 Java 中功能強(qiáng)大的字符輸出流,提供了便捷的文本寫入、格式化輸出和自動刷新等功能,廣泛用于輸出文本數(shù)據(jù)到文件、控制臺或其他輸出流。
import java.io.*;
public class PrintWriterExample {
public static void main(String[] args) {
// PrintWriter寫入(支持格式化和自動刷新)
try (PrintWriter pw = new PrintWriter(new FileWriter("print.txt"), true)) { // 第二個參數(shù)開啟自動刷新
pw.println("PrintWriter便捷輸出");
pw.printf("格式化輸出:%d + %d = %d%n", 2, 3, 5); // 類似printf格式
pw.println("自動刷新生效");
} catch (IOException e) {
e.printStackTrace();
}
// 讀取驗證
try (BufferedReader br = new BufferedReader(new FileReader("print.txt"))) {
System.out.println("PrintWriter寫入內(nèi)容:");
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
6. PipedReader/PipedWriter(管道字符流,線程間通信)
import java.io.*;
public class PipedReadWriteExample {
public static void main(String[] args) throws IOException {
// 創(chuàng)建管道流對(必須綁定)
PipedWriter pw = new PipedWriter();
PipedReader pr = new PipedReader(pw);
// 寫入線程
Thread writerThread = new Thread(() -> {
try {
pw.write("管道流線程間通信數(shù)據(jù)");
pw.close();
} catch (IOException e) {
e.printStackTrace();
}
});
// 讀取線程(并寫入文件)
Thread readerThread = new Thread(() -> {
try (FileWriter fw = new FileWriter("piped.txt")) {
char[] buffer = new char[1024];
int len;
while ((len = pr.read(buffer)) != -1) {
fw.write(buffer, 0, len); // 寫入文件
System.out.println("管道讀取內(nèi)容:" + new String(buffer, 0, len));
}
pr.close();
} catch (IOException e) {
e.printStackTrace();
}
});
writerThread.start();
readerThread.start();
}
}
7. LineNumberReader(帶行號的字符輸入流)
LineNumberReader 是 Java 中帶有行號跟蹤功能的緩沖字符輸入流,繼承自 BufferedReader,在提供高效緩沖讀取的同時,能自動跟蹤當(dāng)前讀取的行號,方便定位文本中的特定行。
import java.io.*;
public class LineNumberReaderExample {
public static void main(String[] args) {
// 先寫入多行數(shù)據(jù)
try (BufferedWriter bw = new BufferedWriter(new FileWriter("linenumber.txt"))) {
bw.write("第一行內(nèi)容");
bw.newLine();
bw.write("第二行內(nèi)容");
bw.newLine();
bw.write("第三行內(nèi)容");
} catch (IOException e) {
e.printStackTrace();
}
// LineNumberReader讀取并跟蹤行號
try (LineNumberReader lnr = new LineNumberReader(new FileReader("linenumber.txt"))) {
lnr.setLineNumber(1); // 設(shè)置起始行號(默認(rèn)從0開始)
String line;
System.out.println("帶行號的內(nèi)容:");
while ((line = lnr.readLine()) != null) {
System.out.printf("第%d行:%s%n", lnr.getLineNumber(), line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
8. PushbackReader(可回退字符的輸入流)
PushbackReader 是 Java 中的一個字符輸入流,繼承自 FilterReader,它的特殊之處在于允許將已讀取的字符 “推回”(回退)到流中。
import java.io.*;
public class Main {
public static void main(String[] args) {
try {
PushbackReader reader =new PushbackReader(new FileReader("file.txt"));
int c;
while((c=reader.read())!=-1){
if(c=='o'){
reader.unread(c);
break;
}
System.out.println(":"+(char)c
);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

總結(jié)
到此這篇關(guān)于Java中流(Stream)、文件(File)和IO的文章就介紹到這了,更多相關(guān)Java流(Stream)、文件(File)和IO內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
線程池ThreadPoolExecutor并行處理實現(xiàn)代碼
這篇文章主要介紹了線程池ThreadPoolExecutor并行處理實現(xiàn)代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-11-11
高內(nèi)聚低耦合原則_動力節(jié)點(diǎn)Java學(xué)院整理
耦合度就是某模塊(類)與其它模塊(類)之間的關(guān)聯(lián)、感知和依賴的程度,是衡量代碼獨(dú)立性的一個指標(biāo),也是軟件工程設(shè)計及編碼質(zhì)量評價的一個標(biāo)準(zhǔn)2017-08-08
Maven?繼承父工程時的relativePath標(biāo)簽詳細(xì)解析
這篇文章主要介紹了Maven?繼承父工程時的relativePath標(biāo)簽解析,通過本文學(xué)習(xí)你需要注意子模塊想要用父模塊pom中的版本,請注意配置relativePath屬性,需要的朋友可以參考下2022-12-12
Java基于FFmpeg實現(xiàn)Mp4視頻轉(zhuǎn)GIF
FFmpeg是一套可以用來記錄、轉(zhuǎn)換數(shù)字音頻、視頻,并能將其轉(zhuǎn)化為流的開源計算機(jī)程序。本文主要介紹了在Java中如何基于FFmpeg進(jìn)行Mp4視頻到Gif動圖的轉(zhuǎn)換,感興趣的小伙伴可以了解一下2022-11-11
java用靜態(tài)工廠代替構(gòu)造函數(shù)使用方法和優(yōu)缺點(diǎn)
這篇文章主要介紹了java用靜態(tài)工廠代替構(gòu)造函數(shù)使用方法和優(yōu)缺點(diǎn),需要的朋友可以參考下2014-02-02
Java如何獲取HttpServletRequest請求參數(shù)
我們常需要接口接收第三方推送的數(shù)據(jù),由于第三方可能不具備開發(fā)能力,我們需要自行解析推送的數(shù)據(jù)格式,通過HttpServletRequest,我們可以解析字符串、JSON、XML以及文件等多種數(shù)據(jù)類型,本文介紹了如何在Java中使用HttpServletRequest獲取請求參數(shù),感興趣的朋友一起看看吧2024-11-11

