------- android培训、java培训、期待与您交流! ----------
ASCII------------1个字节7位表示
GBK-----------2字节
GBK2312-------3字节
Iso8859-1-------唯一一个码表全部有对应值得码表,欧洲人的码表
平台默认的码表在中国是GBK
unicode是一个标准,WINDOWS中unicode默认使用了utf-16
utf-8-------英文1字节 中文3字节
utf-16------所有都是2字节,并且有-2、-1两个标志位
package it.heima.io;
import java.io.UnsupportedEncodingException;
public class GbkDemo {
public static void main(String[] args) throws Exception {
String s="你好";
byte[] buf=s.getBytes("UTF-8");
System.out.println(new String(buf,"GBK"));
System.out.println(new String(buf,"utf-8"));
}
}
package it.heima.io;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
public class OutputSreamReaderDemo {
public static void main(String[] args) throws IOException {
OutputStreamWriter outputStreamWriter=new OutputStreamWriter(new FileOutputStream("F:\\d.txt"), "GBK");
//Write类的5种write方法
outputStreamWriter.write("中");
outputStreamWriter.write(97);
char[] cbuf={'a','v','a','j'};
outputStreamWriter.write(cbuf);
outputStreamWriter.write(cbuf,1,2);
outputStreamWriter.write("我爱java",2,2);
outputStreamWriter.close();
}
}
package it.heima.io;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
public class OutputSreamReaderDemo {
public static void main(String[] args) throws IOException {
InputStreamReader inputStreamReader=new InputStreamReader(new FileInputStream("F:\\d.txt"),"GBK");
int len;
/*char[] cbuf=new char[1024];
while((len=inputStreamReader.read(cbuf))!=-1){
System.out.println(new String(cbuf,0,len));
}*/
while((len=inputStreamReader.read())!=-1)
System.out.print((char)len);
inputStreamReader.close();
}
}
package it.heima.io;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class BufferedWriteDemo {
public static void main(String[] args) throws IOException {
BufferedWriter bufferedWriter=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("F:\\a.txt")));
bufferedWriter.write("中国");
bufferedWriter.write(97);
bufferedWriter.write("中国我爱你",2,3);
char[] cbuf={'是','真','的'};
bufferedWriter.write(cbuf);
bufferedWriter.newLine();
bufferedWriter.write(cbuf,1,2);
bufferedWriter.close();
BufferedReader bufferedReader=new BufferedReader(new FileReader("F:\\a.txt"));
String line=null;
int len;
char[] rbuf=new char[1024];
/*while((len=bufferedReader.read(rbuf))!=-1){
System.out.println(new String(rbuf));
}*/
/*while((len=bufferedReader.read())!=-1){
System.out.print((char)len);
}*/
while((line=bufferedReader.readLine())!=null){
System.out.println(line);
}
}
}
package it.heima.io;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
/*
* 打印流:
* 字节打印流 PrintOutputStream
* 字符打印流 PrintWriter
* */
public class PrintDemo {
public static void main(String[] args) throws IOException {
PrintWriter printWriter=new PrintWriter("F:\\a.txt");//直接传目的地
//可以直接输入任意类型的
printWriter.println("hello");
printWriter.print(true);
printWriter.print(100);
printWriter.close();
//自动刷新
PrintWriter printWriter2=new PrintWriter(new FileWriter("F:\\b.txt"),true);//也可以传一个Writer
//只能是println,printf,format这三个才能自动刷新,print不行
printWriter2.println("hao");
printWriter2.println(true);
printWriter2.close();//不用来刷新,但还是要释放资源
}
}
package cm.itcast.hometest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.SequenceInputStream;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Vector;
//SequenceInputStream的作用:合并流
//SequenceInputStream的两种构造方法
//SequenceInputStream(FileInputStream f1,FileInputStream f2)
//SequenceInputStream(Enumeration) Enumeration是Vector的迭代器,有两种使用方法
public class SequenceDemo {
static int num;
public static void main(String[] args) throws IOException {
//cutMusic();
combineMusic();
}
/*分割音乐文件步骤:
* 创建输入路径
*
* 计算分割成几份
* 创建输出路径及文件
*
*
* */
public static void cutMusic() throws IOException{
File file=new File("F:\\喜欢你.mp3");
FileInputStream fileInputStream=new FileInputStream(file);
//计算分割成几份
long length=file.length();
if(length%(1024*1024)==0){
num=(int)(length/(1024*1024));
}else{
num=(int)(length/(1024*1024))+1;
}
byte[] buf=new byte[1024*1024];//创建1M的数组
for(int i=0;i<num;i++){
int len=fileInputStream.read(buf);
FileOutputStream fileOutputStream=new FileOutputStream("F:\\"+i+".mp3");
fileOutputStream.write(buf,0,len);
fileOutputStream.close();
}
fileInputStream.close();
}
//合并用SequenceInputStream
public static void combineMusic() throws IOException{
File file=new File("F:\\");
Vector<FileInputStream> v1=new Vector<>();
File[] fileList=file.listFiles();
for(File item:fileList){
if(item.getName().endsWith(".mp3")){
v1.add(new FileInputStream(item));
}
}
//v1.elements返回一个迭代器
SequenceInputStream inputStream=new SequenceInputStream(v1.elements());
FileOutputStream fileOutputStream=new FileOutputStream("F:\\喜欢你11.mp3");
int len=0;
byte[] buf=new byte[1024*1024];
while((len=inputStream.read(buf))!=-1){
fileOutputStream.write(buf, 0, len);
}
fileOutputStream.close();
inputStream.close();
}
}
package cm.itcast.hometest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
public class SequenceDemo2 {
public static void main(String[] args) throws IOException {
//cutMusic();
combineMusic();
}
public static void cutMusic() throws IOException {
File file = new File("F://1.pdf");
FileInputStream fileInputStream = new FileInputStream(file);
// 计算分割数
long size = file.length();
int num;
if (size % (1024 * 1024) == 0) {
num = (int) (size / (1024 * 1024));
} else {
num = (int) (size / (1024 * 1024) + 1);
}
int length;
byte[] buf = new byte[1024 * 1024];
for (int i = 0; i < num; i++) {
FileOutputStream fileOutputStream = new FileOutputStream("F:\\" + i + ".mp3");
length = fileInputStream.read(buf);
fileOutputStream.write(buf, 0, length);
fileOutputStream.close();
}
fileInputStream.close();
}
public static void combineMusic() throws IOException {
File file = new File("F:\\");
ArrayList<FileInputStream> arrayList = new ArrayList<>();
File[] files = file.listFiles();
for (File item : files) {
if (item.getName().endsWith(".mp3")) {
FileInputStream fileInputStream=new FileInputStream(item);
arrayList.add(fileInputStream);
}
}
final Iterator<FileInputStream> it=arrayList.iterator();
SequenceInputStream inputStream = new SequenceInputStream(new Enumeration<InputStream>() {
@Override
public boolean hasMoreElements() {
return it.hasNext();
}
@Override
public InputStream nextElement() {
return it.next();
}
});
//这里用mp3会出现一直读一直写的问题,因为我将MP3所有文件都读成输入流了。
FileOutputStream fileOutputStream=new FileOutputStream("F://100.pdfs");
byte[] buf=new byte[1024*1024];
int length=0;
System.out.println("11111111111111");
while((length=inputStream.read(buf))!=-1){
fileOutputStream.write(buf,0,length);
fileOutputStream.flush();
//System.out.println(length);
}
fileOutputStream.close();
inputStream.close();
}
}
对象的序列化:实际就是将一个对象存入到txt文档。
对象的反序列化:实际就是将一个对象从txt文档读出
序列化和反序列化的对象要实现Serializable接口。
Serializable这个接口没有方法。那么这个接口就是一个标记接口。
写入对象:ObjectOutputStream的WriteObject()方法。
读出对象:ObjectInputStream的ReadObject()方法。
序列化注意事项:每个文件只能写入一个对象。
原因:每个对象的序列化都会生成一个private final long serivalVersionUID,在进行反序列化时,JVM会把传来的字节流中的serialVersionUID与本地相 应实体(类)的serialVersionUID进行比较,如果相同就认为是一致的,可以进行反序列化,否则就会出现序列化版本不一致的异常。而每次反序列化J VM会识别第一个servailVersionUID并跳过。遇到第二个对象的ServailVersionUID时会当做对象读取,读取会有异常。
最好自定义一个private final long servailVersionUID的值。
package cn.itcast.enumeration;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
public class ObjectOutputStreamDemo {
public static void main(String[] args) throws IOException, ClassNotFoundException {
/*ArrayList<Person> list=new ArrayList<>();
Address address=new Address("中国", "广州");
list.add(new Person("张三", address, 10));
list.add(new Person("李四", address, 20));
*/
/*这是写/读一个对象的代码
* //创建文件路径
//FileOutputStream fileOutputStream=new FileOutputStream("F:\\Person.txt");
//FileInputStream fileInputStream=new FileInputStream("F:\\Person.txt");
//创建工具流
ObjectOutputStream obj=new ObjectOutputStream(fileOutputStream);
//ObjectInputStream objIn=new ObjectInputStream(fileInputStream);
//obj.writeObject(list);
ArrayList<Person> nlist=(ArrayList<Person>)objIn.readObject();
System.out.println(nlist);
}*/
/*写 没问题,读对象时出现异常
* Address address=new Address("中国", "广州");
Person p1=new Person("张三", address, 10);
Person p2=new Person("李四", address, 20);
FileOutputStream fileOutputStream=new FileOutputStream("F:\\Person.txt");
FileInputStream fileInputStream=new FileInputStream("F:\\Person.txt");
//创建工具流
//ObjectOutputStream obj=new ObjectOutputStream(fileOutputStream);
ObjectInputStream objIn=new ObjectInputStream(fileInputStream);
//obj.writeObject(p1);
//obj.writeObject(p2);
Person p=(Person) objIn.readObject();
System.out.println(p);*/
}
}
class Person implements Serializable{
private final long serialVersionUID =10;
String name;
Address address;
int age;
transient int num;
transient String score;
public Person(String name, Address address, int age) {
super();
this.name = name;
this.address =address;
this.age = age;
}
@Override
public String toString() {
return "Person [name=" + name + ", address=" + address + ", age=" + age + "]";
}
}
class Address implements Serializable{
String country;
String city;
public Address(String country, String city) {
super();
this.country = country;
this.city = city;
}
@Override
public String toString() {
return "Address [country=" + country + ", city=" + city + "]";
}
}
Properties是一个属于MAP体系HashMap的集合。Properties的内容以键值对存在。
通过Properties的setProperties(Stringkey,String value)将对象存入到集合。
通过Properties的store(fileOutputStream,comments)方法可以将集合内容存入进配置文件。
Store()方法内会调用flush方法
通过Properties的load(InputSream)和load(Reader)可以读取配置文件。
通过Set<Entry<Object,Object>>set=p.entrySet()遍历。
注意:通过字节流和字符流都可以传入properties中的键值对。但是要传入中文的话要用字符流
注意:我的错误:导包时Entry导包错误。
properties的代码练习:
package cm.itcast.hometest;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
public class PropertiesDemo {
public static void main(String[] args) throws IOException {
Properties properties=new Properties();
properties.setProperty("张三", "100");
properties.setProperty("李四", "120");
/* 字节流中文有乱码,字符流改进
FileOutputStream out=new FileOutputStream("F:\\1.txt");
properties.store(out, "conment");
*/
FileWriter fileWriter=new FileWriter("F:\\1.txt");
properties.store(fileWriter," comments");
FileReader fileReader=new FileReader("F:\\1.txt");
properties.load(fileReader);
//遍历方法一
/*Set<Entry<Object, Object>> entrys=properties.entrySet();
for(Entry<Object, Object> entry:entrys){
System.out.println(entry.getKey());
System.out.println(entry.getValue());
}*/
//遍历方法二
Set<String> key=properties.stringPropertyNames();
for(String k:key){
System.out.println(k);
System.out.println(properties.getProperty(k));
}
}
}
前言 很多年前写的老文章,备份之:DS算法是在运动搜索中使用最为广泛的搜索算法之一,有的地方被翻译成钻石搜索,菱形搜索。不管是硬件还是软件的视频编码器中,都可以看到它的存在。下面文章的内容主要从学报上摘录,希望给视频算法的新手们有些许帮助。 原理 通常,运动矢量总是高度集中在搜索窗口的中心附近。这对于物体作缓慢运动的视频序列来说更加明显,因为静止块和缓慢运动块占主导地位。运动矢_1671465600
console.log( undefined == null ) //true有文章对此进行了解释,大致是下面的意思:undefined的布尔值是false,null的布尔值也是false,所以它们在比较时都转化为了false,所以 undefined == null 。好吧,上面的解释是错误的。可以从Javascript规范中找到答案:规范中提到, 要比较相等性之前,不能将...
KrbException: Cannot locate default realm解决办法1)拷贝需要组件的配置文件到项目中的 /resources/目录。如hadoop,目录/etc/hadoop/conf/2)代码中写入如下代码System.setProperty("java.security.krb5.conf", "D:\\work\\conf\\k...
最近在使用pack_padded_sequence出现了RuntimeError: Length of all samples has to be greater than 0, but found an element in ‘lengths’ that is <= 0这个错误,刚开始百思不得其解,后来发现 问题出现在pack_padded_sequence(seq, seq_lengths, batch_first=True, enforce_sorted=False),里面的参数seq_leng
postman 模拟微信请求在请求头中添加User-Agent模拟微信请求,其他参数正常添加。
继续此前的文章,使用vlc播放了rtsp流媒体视频后,想检测视频中的人脸,之前采用了opencv但是遇到低头、抬头和侧脸时候,效果就不太好。所以本篇介绍如何使用mtcnn来检测视频中的人脸。大致流程:一、Tensorflow 模型固化将PNet、ONet、RNet 网络参数.npy固化成.pb格式,方便java载入, 固化后的文件在assets中,文件名mtcnn_freezed_model...
https://wenku.baidu.com/view/05e8f71afbd6195f312b3169a45177232f60e474.html?from=searchJAVA常见面试题及解答2015版JAVA面试题大全(含答案)转载于:https://www.cnblogs.com/xtdxs/p/6664201.html...
JobTracker 是一个 master 服务,软件启动之后 JobTracker 接收 Job,负责调度 Job的每一个子任务, task 运行于 TaskTracker 上,并监控它们,如果发现有失败的 task 就重新运行它。一般情况应该把 JobTracker 部署在单独的机器上。TaskTracker 是运行在多个节点上的 slaver 服务。TaskTracker 主动与 Job...
MOV 指令将源操作数复制到目的操作数。作为数据传送(data transfer)指令,它几乎用在所有程序中。在它的基本格式中,第一个操作数是目的操作数,第二个操作数是源操作数:MOV destination,source其中,目的操作数的内容会发生改变,而源操作数不会改变。这种数据从右到左的移动与 C++ 或 Java 中的赋值语句相似:dest = source;在几乎所有的汇编语言指令中,左...
相信很多人对于0x80(单片机0x80什么意思)并不是非常的了解,因此小编在这里为您详解的讲解一下相关信息!0x80这是十六进制数,变成十进制数为-128,因为char型在C语言中范围为-128~127,并不是0乘以80,c语言中乘以用*,例如0*80,表示0乘以80。扩展资料:C语言是一.0x81 10000000或00000001这是区分汉字编码的 汉字编码区别于其他编码的标志就是汉字编码的最...
import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;public class demo001 { public static void main(String[] args) throws InterruptedException { Date date1 =
承接安装系列环境背景:Hive默认使用MapReduce作为执行引擎,即Hive on mr。实际上,Hive还可以使用Tez和Spark作为其执行引擎,分别为Hive on Tez和Hive on Spark。由于MapReduce中间计算均需要写入磁盘,而Spark是放在内存中,所以总体来讲Spark比MapReduce快很多。因此,Hive on Spark也会比Hive on m...