e2lc5's blog

e2lc5's blog

1.错误

1
2
3
4
Expression #1 of SELECT list is not in GROUP BY clause and contains
nonaggregated column ‘数据库名.表名.字段名’ which is not functionally dependent
on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by

2. 查看sql_mode的语句

1
select @@GLOBAL.sql_mode;

3. 解决

1
2
set SQL_MODE = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
SET @@global.sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

执行的sql语句

1
2
3
4
5
6
CREATE TABLE `tb_task_site` (
`id` varchar(40) NOT NULL COMMENT 'id',
`start_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '同步开始时间',
`end_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '同步结束时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

错误提示

1
[ERR] 532> 1067 - Invalid default value for 'end_date'

原因解析

mysql5.7对sql_mode的设置比mysql5.6更严格了,mysql5.6默认的sql_mode:

1
NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

mysql5.7默认sql_mode:

1
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

其中 NO_ZERO_IN_DATE,NO_ZERO_DATE 两个参数使得时间或日期参数 不得 使用0作默认值,也就是上面的sql中 “default ‘0000-00-00 00:00:00’ ”是不被允许的,所以导致该错误提示。

可以通过 select @@sql_mode; 查看自己的mysql设置的sql_mode的值。

sql_mode 使得 sql 语句更严谨,但是又会带来老版本的不兼容问题,所以可以设置sql_mode的值使得新版本兼容老版本的sql脚本。

解决方案
既然是那两个sql_mode参数导致的问题,那就将两个参数去掉就好了。在默认的sql_mode参数去除,只剩下:

1
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

解决方法有如下几种:

1、暂时解决方案,可以在该会话(session)中暂时修改其sql_mode参数,但是会话结束,下一次会话,修改的参数就失效,变为原来的参数。

1
set SQL_MODE = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

执行完之后就可以继续执行建表语句,但是重启mysql后再执行建表语句的话依旧会报错。

2、永久解决方案,可以通过执行sql方式,设置全局sql_mode参数,设置后效果永久生效。

1
set GLOBAL sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81) ~[HikariCP-3.2.0.jar:na]
at com.jfinal.plugin.hikaricp.HikariCpPlugin.start(HikariCpPlugin.java:222) ~[jfinal-4.3.jar:na]
at com.hongjin.jfinaldb.JfinalDbRunner.runDataConfig(JfinalDbRunner.java:54) ~[hongjin-starter-data-jfinaldb-0.0.1-20210903.055800-79.jar:0.0.1-SNAPSHOT]
at com.hongjin.jfinaldb.JfinalDbRunner.run(JfinalDbRunner.java:45) ~[hongjin-starter-data-jfinaldb-0.0.1-20210903.055800-79.jar:0.0.1-SNAPSHOT]
at com.hongjin.jfinaldb.JfinalDbRunner.onApplicationEvent(JfinalDbRunner.java:133) ~[hongjin-starter-data-jfinaldb-0.0.1-20210903.055800-79.jar:0.0.1-SNAPSHOT]
at com.hongjin.jfinaldb.JfinalDbRunner.onApplicationEvent(JfinalDbRunner.java:27) ~[hongjin-starter-data-jfinaldb-0.0.1-20210903.055800-79.jar:0.0.1-SNAPSHOT]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:402) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:359) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.boot.context.event.EventPublishingRunListener.running(EventPublishingRunListener.java:105) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.SpringApplicationRunListeners.running(SpringApplicationRunListeners.java:78) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:332) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at com.hongjin.FoodRestApplication.main(FoodRestApplication.java:14) ~[classes/:na]
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:361) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:777) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:486) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:202) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1452) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.NativeSession.connect(NativeSession.java:165) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825) ~[mysql-connector-java-8.0.16.jar:8.0.16]
... 26 common frames omitted
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at java.base/sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:170) ~[na:na]
at java.base/sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:103) ~[na:na]
at java.base/sun.security.ssl.TransportContext.kickstart(TransportContext.java:238) ~[na:na]
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:404) ~[na:na]
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:383) ~[na:na]
at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:316) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:352) ~[mysql-connector-java-8.0.16.jar:8.0.16]
... 33 common frames omitted

2022-08-08 16:03:05.942 ERROR 3044 --- [ main] o.s.boot.SpringApplication : Application run failed

com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:576) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:562) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81) ~[HikariCP-3.2.0.jar:na]
at com.jfinal.plugin.hikaricp.HikariCpPlugin.start(HikariCpPlugin.java:222) ~[jfinal-4.3.jar:na]
at com.hongjin.jfinaldb.JfinalDbRunner.runDataConfig(JfinalDbRunner.java:54) ~[hongjin-starter-data-jfinaldb-0.0.1-20210903.055800-79.jar:0.0.1-SNAPSHOT]
at com.hongjin.jfinaldb.JfinalDbRunner.run(JfinalDbRunner.java:45) ~[hongjin-starter-data-jfinaldb-0.0.1-20210903.055800-79.jar:0.0.1-SNAPSHOT]
at com.hongjin.jfinaldb.JfinalDbRunner.onApplicationEvent(JfinalDbRunner.java:133) ~[hongjin-starter-data-jfinaldb-0.0.1-20210903.055800-79.jar:0.0.1-SNAPSHOT]
at com.hongjin.jfinaldb.JfinalDbRunner.onApplicationEvent(JfinalDbRunner.java:27) ~[hongjin-starter-data-jfinaldb-0.0.1-20210903.055800-79.jar:0.0.1-SNAPSHOT]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:402) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:359) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.boot.context.event.EventPublishingRunListener.running(EventPublishingRunListener.java:105) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.SpringApplicationRunListeners.running(SpringApplicationRunListeners.java:78) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:332) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at com.hongjin.FoodRestApplication.main(FoodRestApplication.java:14) ~[classes/:na]
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) ~[HikariCP-3.2.0.jar:na]
... 18 common frames omitted
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:361) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:777) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:486) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:202) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1452) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.NativeSession.connect(NativeSession.java:165) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825) ~[mysql-connector-java-8.0.16.jar:8.0.16]
... 26 common frames omitted
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at java.base/sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:170) ~[na:na]
at java.base/sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:103) ~[na:na]
at java.base/sun.security.ssl.TransportContext.kickstart(TransportContext.java:238) ~[na:na]
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:404) ~[na:na]
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:383) ~[na:na]
at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:316) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:352) ~[mysql-connector-java-8.0.16.jar:8.0.16]
... 33 common frames omitted

如果出现SSLHandshakeException 可尝试添加&useSSL=false 到mysql连接地址

//进入/system/xbin目录下,查看是否有sqlite3
cd /system/xbin
ls -a | grep sqlite3
//有sqlite3,退回到windows系统
exit

//将sqlite3复制到windows下面
adb -s emulator-5554 pull /system/xbin/sqlite3

mount -o remount,rw /system

//退回到windows系统
exit

//将sqlite3复制到/system/xbin目录下面
adb -s 127.0.0.1:7555 push sqlite3 /system/xbin/

//重新进入MuMu模拟器,确保是root#用户
adb -s 127.0.0.1:7555 shell

// 给sqlite3命令可执行权限
chmod 755 /system/xbin/sqlite3

//重现将/system目录变为只读
mount -o remount,ro /system

1.Glide使用.placeholder()展占位图之后,下载图片之后会缩放一下。这是因为你的展位图跟下载的图片的尺寸不一样,而Glide本身有一个淡入淡出效果的动画来显示加载的图片,这样两张不一样的图片造成图片下载刚开始是占位尺寸之后淡入淡出到实际加载图片大小,只要使用.dontanimate()取消淡入淡出效果即可。
2.Glide加载图片之后,点击本图片跳转到查看图片详情的大图,这时候大图会重新加载。我的产品说两张图一样,为什么要重新加载,呃大哥其实两张尺寸不一样哦!算了实现吧,我第一个想法就是通过.override(500, 500)方法来把大图的尺寸跟原来的尺寸配置一样,这时候确实点击原图不需要重新加载直接显示了大图预览,但是大图预览需要可以拉伸,需要缩放,这时候限定大小的图片就难以实现放大功能,只能在一个500*500的框里进行。最后找到解决方案–> Glide.with(this).load(URL)).override(Target.SIZE_ORIGINAL,Target.SIZE_ORIGINAL).placeholder(R.mipmap.uf_uf).into(imageview);即是直接下载图片的原图,Target.SIZE_ORIGINAL是指图片原图的大小,这样就可以保证图片的一致性,本地和预览界面可以搁置设置。
3.Glide加载图片出现空白问题,问题描述:Recyclerview嵌套Recyclerview时,被嵌套的Recyclerview的适配器Adapter中的图片设置自适应,那么滑动到之前的位置,图片有时显示空白,解决方案是要给Adapter图片设置具体大小,这样glide不会每次都去下载新的图片而是复用之间就有的。

1

‘com.fivehundredpx:blurringview:1.0.0’

2

compile’com.github.bumptech.glide:glide:3.7.0’
compile’jp.wasabeef:glide-transformations:2.0.1’

3

1、如果系统的api在16以上,可以使用系统提供的方法直接处理图片

1
2
3
4
5
6
7
8
9
10
11
12
13
if (VERSION.SDK_INT > 16) {undefined
Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(radius /* e.g. 3.f */);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
return bitmap;
}

2、 如果Api条件不满足,可以使用如下方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
  @SuppressLint("NewApi")
public static Bitmap fastblur(Context context, Bitmap sentBitmap, int radius) {
Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
if (radius < 1) {undefined
return (null);
}
int w = bitmap.getWidth();
int h = bitmap.getHeight();
int[] pix = new int[w * h];
// Log.e("pix", w + " " + h + " " + pix.length);
bitmap.getPixels(pix, 0, w, 0, 0, w, h);
int wm = w - 1;
int hm = h - 1;
int wh = w * h;
int div = radius + radius + 1;
int r[] = new int[wh];
int g[] = new int[wh];
int b[] = new int[wh];
int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
int vmin[] = new int[Math.max(w, h)];
int divsum = (div + 1) >> 1;
divsum *= divsum;
int temp = 256 * divsum;
int dv[] = new int[temp];
for (i = 0; i < temp; i++) {undefined
dv[i] = (i / divsum);
}
yw = yi = 0;
int[][] stack = new int[div][3];
int stackpointer;
int stackstart;
int[] sir;
int rbs;
int r1 = radius + 1;
int routsum, goutsum, boutsum;
int rinsum, ginsum, binsum;
for (y = 0; y < h; y++) {undefined
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
for (i = -radius; i <= radius; i++) {undefined
p = pix[yi + Math.min(wm, Math.max(i, 0))];
sir = stack[i + radius];
sir[0] = (p & 0xff0000) >> 16;
sir[1] = (p & 0x00ff00) >> 8;
sir[2] = (p & 0x0000ff);
rbs = r1 - Math.abs(i);
rsum += sir[0] * rbs;
gsum += sir[1] * rbs;
bsum += sir[2] * rbs;
if (i > 0) {undefined
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
} else {undefined
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
}
}
stackpointer = radius;
for (x = 0; x < w; x++) {undefined
r[yi] = dv[rsum];
g[yi] = dv[gsum];
b[yi] = dv[bsum];
rsum -= routsum;
gsum -= goutsum;
bsum -= boutsum;
stackstart = stackpointer - radius + div;
sir = stack[stackstart % div];
routsum -= sir[0];
goutsum -= sir[1];
boutsum -= sir[2];
if (y == 0) {undefined
vmin[x] = Math.min(x + radius + 1, wm);
}
p = pix[yw + vmin[x]];
sir[0] = (p & 0xff0000) >> 16;
sir[1] = (p & 0x00ff00) >> 8;
sir[2] = (p & 0x0000ff);
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
rsum += rinsum;
gsum += ginsum;
bsum += binsum;
stackpointer = (stackpointer + 1) % div;
sir = stack[(stackpointer) % div];
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
rinsum -= sir[0];
ginsum -= sir[1];
binsum -= sir[2];
yi++;
}
yw += w;
}
for (x = 0; x < w; x++) {undefined
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
yp = -radius * w;
for (i = -radius; i <= radius; i++) {undefined
yi = Math.max(0, yp) + x;
sir = stack[i + radius];
sir[0] = r[yi];
sir[1] = g[yi];
sir[2] = b[yi];
rbs = r1 - Math.abs(i);
rsum += r[yi] * rbs;
gsum += g[yi] * rbs;
bsum += b[yi] * rbs;
if (i > 0) {undefined
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
} else {undefined
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
}
if (i < hm) {undefined
yp += w;
}
}
yi = x;
stackpointer = radius;
for (y = 0; y < h; y++) {undefined
// Preserve alpha channel: ( 0xff000000 & pix[yi] )
pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
rsum -= routsum;
gsum -= goutsum;
bsum -= boutsum;
stackstart = stackpointer - radius + div;
sir = stack[stackstart % div];
routsum -= sir[0];
goutsum -= sir[1];
boutsum -= sir[2];
if (x == 0) {undefined
vmin[y] = Math.min(y + r1, hm) * w;
}
p = x + vmin[y];
sir[0] = r[p];
sir[1] = g[p];
sir[2] = b[p];
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
rsum += rinsum;
gsum += ginsum;
bsum += binsum;
stackpointer = (stackpointer + 1) % div;
sir = stack[stackpointer];
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
rinsum -= sir[0];
ginsum -= sir[1];
binsum -= sir[2];
yi += w;
}
}
bitmap.setPixels(pix, 0, w, 0, 0, w, h);
return (bitmap);
}

3、以上方法都存在一个问题,性能较低,下面提供一个C实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
static int* StackBlur(int* pix, int w, int h, int radius) {undefined
int wm = w - 1;
int hm = h - 1;
int wh = w * h;
int div = radius + radius + 1; int *r = (int *)malloc(wh * sizeof(int));
int *g = (int *)malloc(wh * sizeof(int));
int *b = (int *)malloc(wh * sizeof(int));
int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
int *vmin = (int *)malloc(MAX(w,h) * sizeof(int));
int divsum = (div + 1) >> 1;
divsum *= divsum;
int *dv = (int *)malloc(256 * divsum * sizeof(int));
for (i = 0; i < 256 * divsum; i++) {undefined
dv[i] = (i / divsum);
}
yw = yi = 0;
int(*stack)[3] = (int(*)[3])malloc(div * 3 * sizeof(int));
int stackpointer;
int stackstart;
int *sir;
int rbs;
int r1 = radius + 1;
int routsum, goutsum, boutsum;
int rinsum, ginsum, binsum;
for (y = 0; y < h; y++) {undefined
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
for (i = -radius; i <= radius; i++) {undefined
p = pix[yi + (MIN(wm, MAX(i, 0)))];
sir = stack[i + radius];
sir[0] = (p & 0xff0000) >> 16;
sir[1] = (p & 0x00ff00) >> 8;
sir[2] = (p & 0x0000ff);
rbs = r1 - ABS(i);
rsum += sir[0] * rbs;
gsum += sir[1] * rbs;
bsum += sir[2] * rbs;
if (i > 0) {undefined
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
}
else {undefined
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
}
}
stackpointer = radius;
for (x = 0; x < w; x++) {undefined
r[yi] = dv[rsum];
g[yi] = dv[gsum];
b[yi] = dv[bsum];
rsum -= routsum;
gsum -= goutsum;
bsum -= boutsum;
stackstart = stackpointer - radius + div;
sir = stack[stackstart % div];
routsum -= sir[0];
goutsum -= sir[1];
boutsum -= sir[2];
if (y == 0) {undefined
vmin[x] = MIN(x + radius + 1, wm);
}
p = pix[yw + vmin[x]];
sir[0] = (p & 0xff0000) >> 16;
sir[1] = (p & 0x00ff00) >> 8;
sir[2] = (p & 0x0000ff);
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
rsum += rinsum;
gsum += ginsum;
bsum += binsum;
stackpointer = (stackpointer + 1) % div;
sir = stack[(stackpointer) % div];
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
rinsum -= sir[0];
ginsum -= sir[1];
binsum -= sir[2];
yi++;
}
yw += w;
}
for (x = 0; x < w; x++) {undefined
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
yp = -radius * w;
for (i = -radius; i <= radius; i++) {undefined
yi = MAX(0, yp) + x;
sir = stack[i + radius];
sir[0] = r[yi];
sir[1] = g[yi];
sir[2] = b[yi];
rbs = r1 - ABS(i);
rsum += r[yi] * rbs;
gsum += g[yi] * rbs;
bsum += b[yi] * rbs;
if (i > 0) {undefined
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
}
else {undefined
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
}
if (i < hm) {undefined
yp += w;
}
}
yi = x;
stackpointer = radius;
for (y = 0; y < h; y++) {undefined
// Preserve alpha channel: ( 0xff000000 & pix[yi] )
pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
rsum -= routsum;
gsum -= goutsum;
bsum -= boutsum;
stackstart = stackpointer - radius + div;
sir = stack[stackstart % div];
routsum -= sir[0];
goutsum -= sir[1];
boutsum -= sir[2];
if (x == 0) {undefined
vmin[y] = MIN(y + r1, hm) * w;
}
p = x + vmin[y];
sir[0] = r[p];
sir[1] = g[p];
sir[2] = b[p];
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
rsum += rinsum;
gsum += ginsum;
bsum += binsum;
stackpointer = (stackpointer + 1) % div;
sir = stack[stackpointer];
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
rinsum -= sir[0];
ginsum -= sir[1];
binsum -= sir[2];
yi += w;
}
}
free(r);
free(g);
free(b);
free(vmin);
free(dv);
free(stack);
return(pix);
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
fun RecyclerView.setItemCount(
columns: Int,
rows: Int
) {
if (adapter != null && adapter is BaseListAdapter<*, *>) {
(adapter as BaseListAdapter<*, *>).width = width / columns
(adapter as BaseListAdapter<*, *>).height = height / rows
}
}

inline fun RecyclerView.waitForLayout(crossinline f: () -> Unit) = with(viewTreeObserver) {
addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
removeOnGlobalLayoutListener(this)
f()
}
})
}

inline fun RecyclerView.waitForLayout2(crossinline f: () -> Unit) {
viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
viewTreeObserver.removeOnGlobalLayoutListener(this)
f()
}
})
}

// 最终还是这个好用
inline fun RecyclerView.waitForLayout3(crossinline f: () -> Unit) {
viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
if (measuredWidth > 0 && measuredHeight > 0) {
viewTreeObserver.removeOnGlobalLayoutListener(this)
f()
if (adapter != null && adapter is BaseListAdapter<*, *>) {
(adapter as BaseListAdapter<*, *>).width = width / 10
(adapter as BaseListAdapter<*, *>).height = height / 1
(adapter as BaseListAdapter<*, *>).notifyDataSetChanged()
}
}
}
})
}

inline fun <T: View> T.afterMeasured(crossinline f: T.() -> Unit) {
viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
if (measuredWidth > 0 && measuredHeight > 0) {
viewTreeObserver.removeOnGlobalLayoutListener(this)
f()
}
}
})
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

static class MySqlC {
AtomicBoolean free = new AtomicBoolean(true);
private SqlSession session;
private BbItemInfoMapper mapper;

public MySqlC(SqlSession session) {
this.session = session;
this.mapper = session.getMapper(BbItemInfoMapper.class);
}
}

private final ArrayList<MySqlC> connectionLists = new ArrayList<>();

private MySqlC getFreeConnection() {
for (MySqlC connectionList : connectionLists) {
if (connectionList.free.get()) {
return connectionList;
}
}
return null;
}

public void importPlu(String filePath, Long batchId) {
try {
File file = new File(filePath);
CsvReader reader = CsvUtil.getReader();
//设置文件读取的分隔符
reader.setFieldSeparator('|');
String charSet = FileUtils.getCharSet(new BufferedInputStream(new FileInputStream(file)));
//根据特定的编码方式读取File的内容
CsvData data = reader.read(file, Charset.forName(charSet));
if (data == null) {
log.error("read csvData got null");
return;
}
ArrayList<BbItemInfo> nInfoList = new ArrayList<>();
int insertCount = 0;
CsvRow firstRow;
String storeNum = "";
int batchCount = 0;
CountDownLatch countDownLatch = new CountDownLatch(data.getRowCount());

connectionLists.add(new MySqlC(sqlSessionFactory.openSession(ExecutorType.BATCH, false)));
connectionLists.add(new MySqlC(sqlSessionFactory.openSession(ExecutorType.BATCH, false)));
connectionLists.add(new MySqlC(sqlSessionFactory.openSession(ExecutorType.BATCH, false)));
connectionLists.add(new MySqlC(sqlSessionFactory.openSession(ExecutorType.BATCH, false)));

// SqlSession sqlsession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
// BbItemInfoMapper bbItemInfoMapper = sqlsession.getMapper(BbItemInfoMapper.class);

for (int i = 0; i < data.getRowCount(); i++) {
if (i == 0) {
firstRow = data.getRow(i);
log.debug(JSON.toJSONString(firstRow));
storeNum = firstRow.get(6);
countDownLatch.countDown();
} else {
CsvRow row = data.getRow(i);
if (row == null) {
log.warn("line 0 is null ");
} else {
log.debug(JSON.toJSONString(row));
BbItemInfo info = new BbItemInfo();
info.setPlu_btch_nbr(row.get(0));
info.setItm_id(StringUtils.parseStr2Int(row.get(2)));
info.setStr_hier_id(StringUtils.parseStr2Int(row.get(3)));
info.setDspl_descr(row.get(6));
info.setRcpt_descr(row.get(8));
info.setTaxability_cd(row.get(9));
info.setSls_auth_fg(row.get(19));
info.setRtl_prc(row.get(23));
info.setTax_rate1_fg(row.get(47));
info.setTax_rate3_fg(row.get(48));
info.setTax_rate4_fg(row.get(49));
info.setTax_rate5_fg(row.get(50));
info.setTax_rate6_fg(row.get(51));
info.setTax_rate7_fg(row.get(52));
info.setTax_rate8_fg(row.get(53));
info.setSubdep_id(StringUtils.parseStr2Int(row.get(61)));
info.setRcpt_descr1(row.get(78));
info.setRcpt_descr2(row.get(79));
info.setRcpt_descr3(row.get(80));
info.setIntrnl_id(StringUtils.parseStr2Int(row.get(85)));
info.setBns_by_descr(row.get(108));
info.setComp_prc(row.get(110));
info.setVnd_itm_id2(row.get(137));
info.setBatch_id(batchId);
info.setStatus_id(0);
info.setAdd_time(new Date());
info.setOp_code(StringUtils.parseStr2Int(row.get(1)));
info.setStore_num(storeNum);
batchCount++;
nInfoList.add(info);
}
}
if (batchCount > 999) {
long startSave = System.currentTimeMillis();

int finalBatchCount = batchCount;
final ArrayList<BbItemInfo> insertList = nInfoList;
PriorityThreadFactory.getPool().execute(new PriorityThread() {
@Override
public void run() {
MySqlC c;
while ((c = getFreeConnection()) != null) {
c.free.set(false);
commit(insertList, c.session, c.mapper);
c.free.set(true);
for (int j = 0; j < finalBatchCount; j++) {
countDownLatch.countDown();
}
break;
}
}

@Override
public String getThreadName() {
return "t" + System.currentTimeMillis();
}
});

log.info("保存耗费 :" + (System.currentTimeMillis() - startSave) + "ms");
insertCount += batchCount;
batchCount = 0;
nInfoList = new ArrayList<>();
}
}

int finalBatchCount = batchCount;
final ArrayList<BbItemInfo> insertList = nInfoList;
PriorityThreadFactory.getPool().execute(new PriorityThread() {
@Override
public void run() {
MySqlC c;
while ((c = getFreeConnection()) != null) {
commit(insertList, c.session, c.mapper);
for (int j = 0; j < finalBatchCount; j++) {
countDownLatch.countDown();
}
break;
}
}

@Override
public String getThreadName() {
return "t" + System.currentTimeMillis();
}
});

insertCount += batchCount;

countDownLatch.await();
for (int i = 0; i < connectionLists.size(); i++) {
connectionLists.get(i).session.close();
}

log.info(String.format("\n导入itemInfo(" + filePath + "), 单据数:%s, 导入数量:%s ", data.getRowCount(), insertCount));
} catch (Exception e) {
e.printStackTrace();
log.error("导入itemInfo", e);
}
}

public synchronized void commit(List<BbItemInfo> bbItemInfos, SqlSession sqlsession, BbItemInfoMapper bbItemInfoMapper) {
for (BbItemInfo bbItemInfo : bbItemInfos) {
bbItemInfoMapper.insert(bbItemInfo);
}
sqlsession.commit();
sqlsession.clearCache();
}

一段错误的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public boolean zipFile(String zipFileName, File inputFile) {
try {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
zipFileName)); // 创建ZipOutputStream类对象
zip(out, inputFile, ""); // 调用方法
System.out.println("压缩中…"); // 输出信息
out.close(); // 将流关闭
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

private void zip(ZipOutputStream out, File f, String base)
throws Exception { // 方法重载
if (f.isDirectory()) { // 测试此抽象路径名表示的文件是否是一个目录
File[] fl = f.listFiles(); // 获取路径数组
out.putNextEntry(new ZipEntry(base + "/")); // 写入此目录的entry
base = base.length() == 0 ? "" : base + "/"; // 判断参数是否为空
for (int i = 0; i < fl.length; i++) { // 循环遍历数组中文件
zip(out, fl[i], base + fl[i]);
}
} else {
out.putNextEntry(new ZipEntry(base)); // 创建新的进入点
// 创建FileInputStream对象
FileInputStream in = new FileInputStream(f);
int b; // 定义int型变量
System.out.println(base);
while ((b = in.read()) != -1) { // 如果没有到达流的尾部
out.write(b); // 将字节写入当前ZIP条目
}
in.close(); // 关闭流
}
}
0%