一、字節流數組不是對文件進行操作的
二、對操作字符串有很高的性能
案例:字符串的截取所有的字母,不論大小寫
package File類;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
public class ByteArrayStreamDemo {
public static void main(String[] args) {
getLetter();
}
// 截取字符串的字母,不論大小寫
public static void getLetter() {
String name = "12324weff,E3EWF34@#$@!@#";
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(name.getBytes());
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int curr = -1; // 當前所以為-1;
// byteArrayInputStream.read() 獲取ANSI編碼
while ((curr = byteArrayInputStream.read()) != -1) {
// 字母的ANSI編碼為:
if ((curr >= 65 && curr <= 90) || (curr >= 97 && curr <= 122)) {
byteArrayOutputStream.write(curr);
}
}
System.out.println(byteArrayOutputStream.toString());
}
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。