一、简介
1、pom.xml
<!-- csv文件解析依赖 -->
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.4</version>
</dependency>
二、手动解析CSV文件
// 析csv文件并转成bean(方法一)
public static List<CsvFile> getCsvDataMethod1(MultipartFile file) {
ArrayList<CsvFile> csvFileList = new ArrayList<>();

InputStreamReader in = null;
String s = null;
try {
in = new InputStreamReader(file.getInputStream(), "utf-8");
BufferedReader bufferedReader = new BufferedReader(in);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
String[] split = line.split(",");
CsvFile csvFile = new CsvFile();
csvFile.setName(splitResult(split[0]));
csvFile.setTitle(splitResult(split[1]));
csvFile.setNumber(splitResult(split[2]));
csvFile.setType(splitResult(split[3]));
csvFile.setPersonnel(splitResult(split[4]));
csvFile.setTime(splitResult(split[5]));
csvFileList.add(csvFile);
}
} catch (IOException e) {
e.printStackTrace();
}
return csvFileList;
}

去重引号""

private static String splitResult(String once) {
String result = "";
for (int i = 0; i < once.length(); i++) {
if (once.charAt(i) != '"') {
result += once.charAt(i);
}
}
return result;
}
三、openCSV解析CSV文件
/**
* 解析csv文件并转成bean(方法二)
*
* @param file csv文件
* @return 数组
*/
public static List<String[]> getCsvDataMethod2(MultipartFile file) {

List<String[]> list = new ArrayList<String[]>();
int i = 0;
try {
CSVReader csvReader = new CSVReaderBuilder(
new BufferedReader(
new InputStreamReader(file.getInputStream(), "utf-8"))).build();
Iterator<String[]> iterator = csvReader.iterator();
while (iterator.hasNext()) {
String[] next = iterator.next();
//去除第一行的表头,从第二行开始
if (i >= 1) {
list.add(next);
}
i++;
}
return list;
} catch (Exception e) {
System.out.println("CSV文件读取异常");
return list;
}
}

四、openCSV解析CSV文件(结果为实体类)
工具类:

/**
* 解析csv文件并转成bean(方法三)
*
* @param file csv文件
* @param clazz 类
* @param <T> 泛型
* @return 泛型bean集合
*/
public static <T> List<T> getCsvDataMethod3(MultipartFile file, Class<T> clazz) {
InputStreamReader in = null;
CsvToBean<T> csvToBean = null;
try {
in = new InputStreamReader(file.getInputStream(), "utf-8");
HeaderColumnNameMappingStrategy<T> strategy = new HeaderColumnNameMappingStrategy<>();
strategy.setType(clazz);
csvToBean = new CsvToBeanBuilder<T>(in).withMappingStrategy(strategy).build();
} catch (Exception e) {
logger.error("数据转化失败");
return null;
}
return csvToBean.parse();
}

实体类:

import com.opencsv.bean.CsvBindByName;
import lombok.Data;

@Data
public class CsvFile {

@CsvBindByName(column = "name")
private String name;

@CsvBindByName(column = "title")
private String title;

@CsvBindByName(column = "number")
private String number;

@CsvBindByName(column = "type")
private String type;

@CsvBindByName(column = "personnel")
private String personnel;

@CsvBindByName(column = "time")
private String time;
}

五、整理完成的CsvUtils

import com.lydms.testopencsv.domain.CsvFile;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import com.opencsv.bean.CsvToBean;
import com.opencsv.bean.CsvToBeanBuilder;
import com.opencsv.bean.HeaderColumnNameMappingStrategy;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class CsvUtils {
private static final Logger logger = LogManager.getLogger(CsvUtils.class);


/**
* 解析csv文件并转成bean(方法二)
*
* @param file csv文件
* @return 数组
*/
public static List<String[]> getCsvDataMethod2(MultipartFile file) {

List<String[]> list = new ArrayList<String[]>();
int i = 0;
try {
CSVReader csvReader = new CSVReaderBuilder(
new BufferedReader(
new InputStreamReader(file.getInputStream(), "utf-8"))).build();
Iterator<String[]> iterator = csvReader.iterator();
while (iterator.hasNext()) {
String[] next = iterator.next();
//去除第一行的表头,从第二行开始
if (i >= 1) {
list.add(next);
}
i++;
}
return list;
} catch (Exception e) {
System.out.println("CSV文件读取异常");
return list;
}
}


/**
* 解析csv文件并转成bean(方法三)
*
* @param file csv文件
* @param clazz 类
* @param <T> 泛型
* @return 泛型bean集合
*/
public static <T> List<T> getCsvDataMethod3(MultipartFile file, Class<T> clazz) {
InputStreamReader in = null;
CsvToBean<T> csvToBean = null;
try {
in = new InputStreamReader(file.getInputStream(), "utf-8");
HeaderColumnNameMappingStrategy<T> strategy = new HeaderColumnNameMappingStrategy<>();
strategy.setType(clazz);
csvToBean = new CsvToBeanBuilder<T>(in).withMappingStrategy(strategy).build();
} catch (Exception e) {
logger.error("数据转化失败");
return null;
}
return csvToBean.parse();
}


/**
* 解析csv文件并转成bean(方法一)
*
* @param file
* @return
*/
public static List<CsvFile> getCsvDataMethod1(MultipartFile file) {
ArrayList<CsvFile> csvFileList = new ArrayList<>();

InputStreamReader in = null;
String s = null;
try {
in = new InputStreamReader(file.getInputStream(), "utf-8");
BufferedReader bufferedReader = new BufferedReader(in);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
String[] split = line.split(",");
CsvFile csvFile = new CsvFile();
csvFile.setName(splitResult(split[0]));
csvFile.setTitle(splitResult(split[1]));
csvFile.setNumber(splitResult(split[2]));
csvFile.setType(splitResult(split[3]));
csvFile.setPersonnel(splitResult(split[4]));
csvFile.setTime(splitResult(split[5]));
csvFileList.add(csvFile);
}
} catch (IOException e) {
e.printStackTrace();
}
return csvFileList;
}

private static String splitResult(String once) {
String result = "";
for (int i = 0; i < once.length(); i++) {
if (once.charAt(i) != '"') {
result += once.charAt(i);
}
}
return result;
}
}

六、相关地址

参考地址:https://www.cnblogs.com/xhj99/p/13536465.html

git地址:https://github.com/li395092734/test-opencsv

csv地址:https://files.cnblogs.com/files/blogs/604830/csvfile.zip

------------------------------------------------------------------------------------------------------------------------

Java解压缩.gz .zip .tar.gz等格式的压缩包方法总结

一、.gz文件是linux下常见的压缩格式。使用 java.util.zip.GZIPInputStream即可,压缩是 java.util.zip.GZIPOutputStream
public static void unGzipFile(String sourcedir) {
String ouputfile = "";
try {
//建立gzip压缩文件输入流
FileInputStream fin = new FileInputStream(sourcedir);
//建立gzip解压工作流
GZIPInputStream gzin = new GZIPInputStream(fin);
//建立解压文件输出流
ouputfile = sourcedir.substring(0,sourcedir.lastIndexOf('.'));
ouputfile = ouputfile.substring(0,ouputfile.lastIndexOf('.'));
FileOutputStream fout = new FileOutputStream(ouputfile);

int num;
byte[] buf=new byte[1024];

while ((num = gzin.read(buf,0,buf.length)) != -1)
{
fout.write(buf,0,num);
}

gzin.close();
fout.close();
fin.close();
} catch (Exception ex){
System.err.println(ex.toString());
}
return;
}

2、zip文件,使用java.util.zip.ZipEntry 和 java.util.zip.ZipFile
/**
* 解压缩zipFile
* @param file 要解压的zip文件对象
* @param outputDir 要解压到某个指定的目录下
* @throws IOException
*/
public static void unZip(File file,String outputDir) throws IOException {
ZipFile zipFile = null;

try {
Charset CP866 = Charset.forName("CP866"); //specifying alternative (non UTF-8) charset
//ZipFile zipFile = new ZipFile(zipArchive, CP866);
zipFile = new ZipFile(file, CP866);
createDirectory(outputDir,null);//创建输出目录

Enumeration<?> enums = zipFile.entries();
while(enums.hasMoreElements()){

ZipEntry entry = (ZipEntry) enums.nextElement();
System.out.println("解压." + entry.getName());

if(entry.isDirectory()){//是目录
createDirectory(outputDir,entry.getName());//创建空目录
}else{//是文件
File tmpFile = new File(outputDir + "/" + entry.getName());
createDirectory(tmpFile.getParent() + "/",null);//创建输出目录

InputStream in = null;
OutputStream out = null;
try{
in = zipFile.getInputStream(entry);;
out = new FileOutputStream(tmpFile);
int length = 0;

byte[] b = new byte[2048];
while((length = in.read(b)) != -1){
out.write(b, 0, length);
}

}catch(IOException ex){
throw ex;
}finally{
if(in!=null)
in.close();
if(out!=null)
out.close();
}
}
}

} catch (IOException e) {
throw new IOException("解压缩文件出现异常",e);
} finally{
try{
if(zipFile != null){
zipFile.close();
}
}catch(IOException ex){
throw new IOException("关闭zipFile出现异常",ex);
}
}
}

/**
* 构建目录
* @param outputDir
* @param subDir
*/
public static void createDirectory(String outputDir,String subDir){
File file = new File(outputDir);
if(!(subDir == null || subDir.trim().equals(""))){//子目录不为空
file = new File(outputDir + "/" + subDir);
}
if(!file.exists()){
if(!file.getParentFile().exists())
file.getParentFile().mkdirs();
file.mkdirs();
}
}

3、.tar.gz文件可以看做先用tar打包,再使用gz进行压缩。
使用org.apache.tools.tar.TarEntry; org.apache.tools.tar.TarInputStream 和 org.apache.tools.tar.TarOutputStream

需要导入pom文件:

<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.7</version>
</dependency>
package com.asiainfo.utils;

import org.apache.tools.tar.TarEntry;
import org.apache.tools.tar.TarInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.zip.GZIPInputStream;

public class TarGzipParser {
private static final Logger LOGGER = LoggerFactory.getLogger(TarGzipParser.class);

/**
* 解压tar.gz 文件
* @param file 要解压的tar.gz文件对象
* @param outputDir 要解压到某个指定的目录下
* @throws IOException
*/
public static File unTarGz(File file,String outputDir) throws IOException{
TarInputStream tarIn = null;
File tmpFile = null;
try{
tarIn = new TarInputStream(new GZIPInputStream(
new BufferedInputStream(new FileInputStream(file))),
1024 * 2);

createDirectory(outputDir,null);//创建输出目录

TarEntry entry = null;
while( (entry = tarIn.getNextEntry()) != null ){

if(entry.isDirectory()){//是目录
entry.getName();
createDirectory(outputDir,entry.getName());//创建空目录
}else{//是文件
tmpFile = new File(outputDir + "\\" + entry.getName());
createDirectory(tmpFile.getParent() + "\\",null);//创建输出目录
OutputStream out = null;
try{
out = new FileOutputStream(tmpFile);
int length = 0;

byte[] b = new byte[2048];

while((length = tarIn.read(b)) != -1){
out.write(b, 0, length);
}

}catch(IOException ex){
throw ex;
}finally{

if(out!=null)
out.close();
}
}
}
}catch(IOException ex){
throw new IOException("解压归档文件出现异常",ex);
} finally{
try{
if(tarIn != null){
tarIn.close();
}
}catch(IOException ex){
throw new IOException("关闭tarFile出现异常",ex);
}
}

return tmpFile;
}

/**
* 构建目录
* @param outputDir
* @param subDir
*/
public static void createDirectory(String outputDir,String subDir){
File file = new File(outputDir);
if(!(subDir == null || subDir.trim().equals(""))){//子目录不为空
file = new File(outputDir + "\\" + subDir);
}
if(!file.exists()){
if(!file.getParentFile().exists())
file.getParentFile().mkdirs();
file.mkdirs();
}
}

}

------------------------------------------------------------------------------------------------------------------------

应用场景

在大数据的工作中,每天必不可少的就是和数据打交道,我们需要从我们的业务方将数据采集过来,然后根据我们的业务逻辑将数据解析并转换成我们所需要的格式!大数据分析往往数据量都是非常大的,一天几十T都是很正常,如果按正常的来采集的话,估计就是采集都要花费不少时间,最常用的方式就是将数据进行压缩之后再进行传输,这样的效率是比较高的,也节省了带宽资源!举一个简单的例子,我们的逻辑是xml原始文件先压缩成一个gz文件,再将上百个gz文件再二次压缩成一个tar.gz文件!一个压缩文件的大小大概是200M,但是解压出来就差不多20G!!!此篇文章就记录一下实现功能需求的过程!!!!

依赖

1
2
3
4
5
<dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-compress</artifactId>
            <version>1.5</version>
</dependency>

 实现代码

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
172
173
174
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.io.*;
import java.util.zip.GZIPInputStream;
 
 
@Slf4j
public class FileUtils {
    private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);
 
 
    public static void main(String[] args) {
        deCompressGZipFile("path1""dir1");
    }
 
    /**
     * Tar文件解压方法
     *
     * @param tarGzFile 要解压的压缩文件名称(绝对路径名称)
     * @param destDir   解压后文件放置的路径名(绝对路径名称)当路径不存在,会自动创建
     * @return 解压出的文件列表
     */
    public static void deCompressGZipFile(String tarGzFile, String destDir) {
 
        // 建立输出流,用于将从压缩文件中读出的文件流写入到磁盘
        TarArchiveEntry entry = null;
        TarArchiveEntry[] subEntries = null;
        File subEntryFile = null;
        try (FileInputStream fis = new FileInputStream(tarGzFile);
             GZIPInputStream gis = new GZIPInputStream(fis);
             TarArchiveInputStream taris = new TarArchiveInputStream(gis);) {
            while ((entry = taris.getNextTarEntry()) != null) {
                StringBuilder entryFileName = new StringBuilder();
                entryFileName.append(destDir).append(File.separator).append(entry.getName());
                File entryFile = new File(entryFileName.toString());
                if (entry.isDirectory()) {
                    if (!entryFile.exists()) {
                        entryFile.mkdir();
                    }
                    subEntries = entry.getDirectoryEntries();
                    for (int i = 0; i < subEntries.length; i++) {
                        try (OutputStream out = new FileOutputStream(subEntryFile)) {
                            subEntryFile = new File(entryFileName + File.separator + subEntries[i].getName());
                            IOUtils.copy(taris, out);
                        catch (Exception e) {
                            LOGGER.error("deCompressing file failed:" + subEntries[i].getName() + "in" + tarGzFile);
                        }
                    }
                else {
                    checkFileExists(entryFile);
                    OutputStream out = new FileOutputStream(entryFile);
                    IOUtils.copy(taris, out);
                    out.close();
                    //如果是gz文件进行递归解压
                    if (entryFile.getName().endsWith(".gz")) {
                        String namepath = entryFile.getAbsolutePath();
                        compressGZ(namepath);
                    }
                }
            }
            //如果需要刪除之前解压的gz文件,在这里进行
            File dir = new File("dir1");
            File[] files = dir.listFiles();
            for (File f:files) {
                if (f.getName().split("\\.").length==3){
                    f.delete();
                }
            }
 
 
        catch (Exception e) {
            LOGGER.warn("decompress failed", e);
        }
    }
 
    /**
     * 解压GZ文件
     * @param pwd
     */
    public static void compressGZ(String pwd){
        if (!getExtension(pwd).equalsIgnoreCase("gz")) {
            System.err.println("File name must have extension of \".gz\"");
            System.exit(1);
        }
 
        GZIPInputStream in = null;
        try {
            in = new GZIPInputStream(new FileInputStream(pwd));
        catch(FileNotFoundException e) {
            System.err.println("File not found. " + pwd);
            System.exit(1);
        catch (IOException e) {
            e.printStackTrace();
        }
 
        String outFileName = getFileName(pwd);
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(outFileName);
        catch (FileNotFoundException e) {
            System.err.println("Could not write to file. " + outFileName);
            System.exit(1);
        }
 
        try {
            byte[] buf = new byte[1024];
            int len;
            while((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
        catch (IOException e) {
            e.printStackTrace();
        }
    }
 
 
    /**
     * Used to extract and return the extension of a given file.
     * @param f Incoming file to get the extension of
     * @return <code>String</code> representing the extension of the incoming
     *         file.
     */
    public static String getExtension(String f) {
        String ext = "";
        int i = f.lastIndexOf('.');
 
        if (i > 0 &&  i < f.length() - 1) {
            ext = f.substring(i+1);
        }
        return ext;
    }
 
    /**
     * Used to extract the filename without its extension.
     * @param f Incoming file to get the filename
     * @return <code>String</code> representing the filename without its
     *         extension.
     */
    public static String getFileName(String f) {
        String fname = "";
        int i = f.lastIndexOf('.');
 
        if (i > 0 &&  i < f.length() - 1) {
            fname = f.substring(0,i);
        }
        return fname;
    }
 
    public static void checkFileExists(File file) {
        //判断是否是目录
        if (file.isDirectory()) {
            if (!file.exists()) {
                file.mkdir();
            }
        else {
            //判断父目录是否存在,如果不存在,则创建
            if (file.getParentFile() != null && !file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
            try {
                file.createNewFile();
            catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

这样就实现了将tar.gz文件中的xml原始文件全部解压出来!之后就可以将xml文件中的数据拿出来做解析和分析了!java解析xml文件的方式有多种,这里使用dom4j!!

依赖

1
2
3
4
5
<dependency>
            <groupId>org.dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>2.1.3</version>
</dependency>

 实现代码

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
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
 
/**
 * java  DOM4j  xml解析
 */
 
public class JavaXMLTest {
    public static void main(String[] args) throws IOException, DocumentException {
 
        SAXReader reader = new SAXReader();
        Document xmlDocument = reader.read(new FileInputStream(new File("2.xml")));
        //System.out.println(doc==null?"未读取到xml文件":"已读取到xml文件");
 
        //获取根节点
        Element rootElement = xmlDocument.getRootElement();
        //获取根节点下的直接子节点的个数和名字
        List<Element> list = rootElement.elements("fileHeader");
 
        //System.out.println("根节点下有"+list.size()+"直接子节点");
 
        //获取根节点下  fileHeader节点得value值
        for (Element elemet:list) {
            String reportTime = elemet.attributeValue("reportTime");
            String startTime = elemet.attributeValue("startTime");
            String endTime = elemet.attributeValue("endTime");
        }
 
 
        //获取根节点下所有得  子节点
        List<Element> list1 = rootElement.elements("header");
        //System.out.println("根节点下header有"+list1.size()+"直接子节点");
 
        //由于只有一个节点所以取get(0)
        Element header = list1.get(0);
        //获取header节点得value值
        String id = header.attributeValue("id");
        //System.out.println("id是"+id);
 
        //获取header节点下所有  measure 节点
        Element measure = header.elements("measure").get(0);
        //获取measurement节点下   smr节点
        Element  sm = measure.elements("sm").get(0);
        //获取smr节点的value值
        String stringValue = sm.getStringValue();
        //按照空格进行拆分
        String[] objj = stringValue.split(" ");
        //System.out.println("stringvalue===="+stringValue);
        //List<Element> smlist = smr.elements("obj");
        //获取measure节点下所有的  obj 节点
        List<Element> objlist = measurement.elements("obj");
        //Map<String,String> map = new HashMap();
 
        //遍历所有  obj节点
        for (Element ob:objectlist) {
            //System.out.println(objj.length);
            //获取所有 obj节点 下的 v 节点
            List<Element> vlist = ob.elements("v");
            //遍历  v  节点
            for (Element v:vlist) {
                //System.out.println("v得value值是"+v.getStringValue());
                //获取v节点的value值
                String[] vv = v.getStringValue().split(" ");
                //System.out.println(vv.length);
                StringBuilder sb = new StringBuilder();
                for (int i=0;i<objj.length;i++){
                    sb.append(objj[i]+"="+vv[i]);
                }
                System.out.println(sb.toString());
                sb=null;
            }
        }
    }
}
    

至此,利用java就完成了对tar.gz文件的解压,并对xml原始文件进行数据解析!!!这个方法对于小数据量是可以实现的!但是大数据都是基于分布式文件系统Hadoop构建的!我们的数据都是存储在hdfs上的,而且数据也非常大,这样解压文件写到本地文件系统中,再解析其中的数据上传至hdfs!同时也是要消耗带宽的!最终在测试的时候是不行的!这个方案就被否定了!

java解析CSV文件三种方法(openCSV)的更多相关文章

  1. java解析xml的三种方法

    java解析XML的三种方法 1.SAX事件解析 package com.wzh.sax; import org.xml.sax.Attributes; import org.xml.sax.SAXE ...

  2. java解析XML文件四种方法之引入源文件

    1.DOM解析(官方) try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();         Documen ...

  3. Java解析XML的四种方法详解 - 转载

    XML现在已经成为一种通用的数据交换格式,平台的无关性使得很多场合都需要用到XML.本文将详细介绍用Java解析XML的四种方法 在做一般的XML数据交换过程中,我更乐意传递XML字符串,而不是格式化 ...

  4. 【Java】详解Java解析XML的四种方法

    XML现在已经成为一种通用的数据交换格式,平台的无关性使得很多场合都需要用到XML.本文将详细介绍用Java解析XML的四种方法. AD: XML现在已经成为一种通用的数据交换格式,它的平台无关性,语 ...

  5. (转)Java结束线程的三种方法

    背景:面试过程中问到结束线程的方法和线程池shutdown shutdownnow区别以及底层的实现,当时答的并不好. Java结束线程的三种方法 线程属于一次性消耗品,在执行完run()方法之后线程 ...

  6. JAVA写JSON的三种方法,java对象转json数据

    JAVA写JSON的三种方法,java对象转json数据 转自:http://www.xdx97.com/#/single?bid=5afe2ff9-8cd1-67cf-e7bc-437b74c07a ...

  7. Java结束线程的三种方法(爱奇艺面试)

    线程属于一次性消耗品,在执行完run()方法之后线程便会正常结束了,线程结束后便会销毁,不能再次start,只能重新建立新的线程对象,但有时run()方法是永远不会结束的.例如在程序中使用线程进行So ...

  8. java实现定时任务的三种方法 - 转载

    java实现定时任务的三种方法 /** * 普通thread * 这是最常见的,创建一个thread,然后让它在while循环里一直运行着, * 通过sleep方法来达到定时任务的效果.这样可以快速简 ...

  9. java 获取随机数的三种方法

    方法1(数据类型)(最小值+Math.random()*(最大值-最小值+1))例:(int)(1+Math.random()*(10-1+1))从1到10的int型随数 方法2获得随机数for (i ...

  10. Java导出freemarker的三种方法

    在上一篇呢,我将导出word文档的想法与思路以及实现功能的代码分享了一下,在这里, 我想说的是我对导出freemarker模板路径的三种方法的理解和认知.  有错误的话希望大家帮忙指正 在接下来我会使 ...

随机推荐

  1. docker bulid tag push到自己的docker hub 仓库

    -t(或 --tag)参数:用于给构建的镜像指定标签(tag).标签的格式通常是 [仓库名/][用户名/]镜像名:版本号 -f(或 --file)参数: 指定构建镜像所使用的 Dockerfile 的 ...

  2. 前端稳定性工具-Sentry

    什么是Sentry? Sentry本质上是一个服务器端的应用程序,它接收来自客户端(如Web应用程序.移动应用程序或后端服务)的错误日志,然后对这些日志进行聚合.分析和可视化.它提供了详细的错误报告, ...

  3. 3大策略+1款工具,在K8s上搞定应用零宕机

    原文链接: https://jaadds.medium.com/building-resilient-applications-on-kubernetes-9e9e4edb4d33 翻译:cloudp ...

  4. 微信小游戏sdk接入支付和登录,解决了wx原生不支持ios支付的痛点

    前情提要 微信小游戏是小程序的一种. 项目接入微信小游戏sdk的支付和登录.主要难点在于接入ios的支付.因为官方只支持android, 不支持ios. 即ios用户不能直接在小游戏中发起支付,参考市 ...

  5. [转载]Redis之缓存穿透、缓存击穿、缓存雪崩及其解决方法

    原文地址:https://mp.weixin.qq.com/s?__biz=MzU2MDY0NDQwNQ==&mid=2247483949&idx=1&sn=6c643858d ...

  6. gitlab之配置文件.gitlab-ci.yml

    自动化部署給我们带来的好处 自动化部署的好处体现在几个方面 1.提高前端的开发效率和开发测试之间的协调效率 Before 如果按照传统的流程,在项目上线前的测试阶段,前端同学修复bug之后,要手动把代 ...

  7. Javascript 常用封装(二)

    1.字符串占位宽度 计算占位宽度:字符串的占位宽度除了涉及到具体的字符串内容,还与字体大小有关,可以将其放入Dom中来获取实际占位宽度 //计算字符串的占位宽度 function getTextWid ...

  8. HTML5 拖拽接口

    1.首先,为了使元素可拖动,要先设置元素为可拖拽 方法:添加draggable属性,设置为 true 注意:链接和图像默认就支持拖拽,另外,如果一个元素中的文本被选中,那么这个元素和他的文本节点此时都 ...

  9. ORCA避障源码笔记

    参考资料 https://gamma.cs.unc.edu/ORCA/publications/ORCA.pdf https://gamma.cs.unc.edu/RVO2/ 数学知识 1.向量的点乘 ...

  10. 自底向上的语法分析,闭包、GOTO函数

    自底向上的语法分析 一.一个串ω归约(reduction)为文法开始符号的过程 关键问题: 1.何时进行规约,2.用哪个产生式规约 句柄右边的串ω一定只包含终结符号. 如果文法是无二义性的,那么文法的 ...