首页 > 编程语言 >java+geotools (geotools for java)

java+geotools (geotools for java)

时间:2023-07-04 15:36:55浏览次数:40  
标签:java org geom new import data geotools

geotools所需的依赖,在pom.xml引入;

<dependencies>
    <!-- for geotools begin -->
        <!--处理空间数据-->
        <!-- geotools主要依赖 -->
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-metadata</artifactId>
            <version>27.2</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-referencing</artifactId>
            <version>27.2</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-epsg-wkt</artifactId>
            <version>27.2</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-shapefile</artifactId>
            <version>27.2</version>
        </dependency>

        <!--<dependency>-->
            <!--<groupId>org.geotools</groupId>-->
            <!--<artifactId>gt-data</artifactId>-->
            <!--<version>27.2</version>-->
        <!--</dependency>-->

        <!--<dependency>-->
            <!--<groupId>org.geotools</groupId>-->
            <!--<artifactId>gt-api</artifactId>-->
            <!--<version>27.2</version>-->
        <!--</dependency>-->
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-main</artifactId>
            <version>27.2</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-swing</artifactId>
            <version>27.2</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-jdbc</artifactId>
            <version>27.2</version>
        </dependency>
        <dependency>
            <groupId>org.geotools.jdbc</groupId>
            <artifactId>gt-jdbc-postgis</artifactId>
            <version>27.2</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-opengis</artifactId>
            <version>27.2</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-epsg-hsql</artifactId>
            <version>27.2</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-geojson</artifactId>
            <version>27.2</version>
        </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
     <artifactId>gt-process-feature</artifactId>
     <version>27.2</version>
    </dependency>

     <dependency> <groupId>org.locationtech.jts</groupId> <artifactId>jts-core</artifactId> <version>1.18.2</version> </dependency> <!--for geotools end--> <!--读取geojson文件--> <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>org.wowtools</groupId> <artifactId>giscat-vector-pojo</artifactId> <version>1.1.1-STABLE</version> </dependency> <!--读取geojson文件end--> </dependencies> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>https://repo.spring.io/snapshot</url> <releases> <enabled>false</enabled> </releases> </repository> <!-- geotools的远程库 --> <repository> <id>osgeo</id> <name>OSGeo Release Repository</name> <url>https://repo.osgeo.org/repository/release/</url> <snapshots><enabled>false</enabled></snapshots> <releases><enabled>true</enabled></releases> </repository> <repository> <id>osgeo-snapshot</id> <name>OSGeo Snapshot Repository</name> <url>https://repo.osgeo.org/repository/snapshot/</url> <snapshots><enabled>true</enabled></snapshots> <releases><enabled>false</enabled></releases> </repository> <!-- geotools的远程库end --> </repositories>

 下面是封装的一些方法(读取shp、读取geojson文件、读取属性attribute、查询...)

package com.example.demo.mapper;

import org.geotools.data.DefaultTransaction;
import org.geotools.data.FeatureSource;
import org.geotools.data.Transaction;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.shapefile.ShapefileDataStoreFactory;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.data.simple.SimpleFeatureStore;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.filter.text.cql2.CQL;
import org.geotools.geojson.GeoJSON;
import org.geotools.geojson.feature.FeatureJSON;
import org.geotools.geojson.geom.GeometryJSON;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.geotools.util.factory.GeoTools;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.MultiPolygon;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Polygon;
import org.opengis.feature.Property;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory2;
import org.springframework.stereotype.Component;

import java.io.*;
import java.net.MalformedURLException;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.*;
@Component
public class GeoToolsMethod {
//使用openGIS FilterFactory2
private static org.opengis.filter.FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
//读取shp
public FeatureSource<SimpleFeatureType, SimpleFeature> ReadShpFile(String filePath) throws Exception{
File dir = new File(filePath);
File[] subFiles = dir.listFiles();
if (null!=subFiles){
for (File subFile : subFiles) {
if (subFile.getName().endsWith(".shp")) {
filePath = subFile.getPath();break;
}
}
}
File shpFile = new File(filePath);
//源shape文件
//ShapefileDataStore shpDataStore = (ShapefileDataStore) new ShapefileDataStoreFactory().createDataStore(subFile.toURI().toURL());
ShapefileDataStore shpDataStore = new ShapefileDataStore(shpFile.toURI().toURL());
shpDataStore.setCharset(Charset.forName("UTF-8"));
FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = shpDataStore.getFeatureSource();
return featureSource;
}
//读取geojson
public FeatureCollection ReadGeojsonFile(String pathfile) throws Exception{
FeatureCollection featureCollection = null;
//创建一个JSONParser对象
JSONParser jsonParser = new JSONParser();
//解析JSON文件的内容
try {
//String pathfile = getClass().getClassLoader().getResource("csdata").getPath()+"/csfeature.geojson";
//先用json.simple读取geojson文件
// org.json.simple.JSONObject obj = (org.json.simple.JSONObject) jsonParser.parse(new FileReader("D:/hjyTest/JAVA/demo_gdal2/target/classes/csdata/csfeature.geojson"));
JSONObject obj = (JSONObject) jsonParser.parse(new FileReader(pathfile));
//JSONObject obj = (JSONObject) jsonParser.parse(new FileReader("E:\\河南省乡镇点\\FieldPolygon.geojson"));
//删除除features以外其它对象,方便下面所需的geojson字符串
// obj.remove("type");
// obj.remove("name");
// obj.remove("crs");
//获取features对象json字符串
String strGeoJson =obj.toString();
System.out.println(strGeoJson);


// 指定GeometryJSON构造器,15位小数
FeatureJSON fjson_15 = new FeatureJSON(new GeometryJSON(15));
// fjson_15已经保留15位
fjson_15.setEncodeFeatureCollectionCRS(true);
fjson_15.setEncodeNullValues(true);

featureCollection = fjson_15.readFeatureCollection(strGeoJson);
fjson_15.writeFeatureCollection(featureCollection,System.out); // 控制台输出和原始geojson一致



// OutputStream ostream = new ByteArrayOutputStream();
// GeoJSON.write(featureCollection, ostream);
// // 输出:{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[116.1983,39.7832],[116.0445,39.2323],[116.8959,39.3831],[116.8698,39.9182],[116.1983,39.7832]]]},"properties":{"area":3865207830},"id":"polygon.1"}]}
// System.out.println(ostream);

// //获取数据
// FeatureIterator<SimpleFeature> iterator = featureCollection.features();
// while(iterator.hasNext()) {
// SimpleFeature feature = iterator.next();
// try{
// org.locationtech.jts.geom.Geometry geom1 = (org.locationtech.jts.geom.Geometry) feature.getDefaultGeometry();
// System.out.println(geom1.getCoordinate());
// }catch (Exception e){
//
// }
//
//
// feature.getName();
// Iterator<Property> it = feature.getProperties().iterator();
// LinkedHashMap<String, Object> data = new LinkedHashMap<>();
// String geometry = "";
// while (it.hasNext()) {
// Property pro = it.next();
// if (pro.getValue() instanceof org.locationtech.jts.geom.Point) {//点
// geometry = "'" + ((org.locationtech.jts.geom.Point) pro.getValue()).toString() + "'";
// data.put("geom", geometry);
// } else if (pro.getValue() instanceof org.locationtech.jts.geom.Polygon) {//面
// geometry = "'" + ((org.locationtech.jts.geom.Polygon) pro.getValue()).toString() + "'";
// data.put("geom", geometry);
// } else if (pro.getValue() instanceof org.locationtech.jts.geom.MultiPolygon) {//多面
// geometry = "'" + ((org.locationtech.jts.geom.MultiPolygon) pro.getValue()).toString() + "'";
// data.put("geom", geometry);
// } else if (pro.getValue() instanceof org.locationtech.jts.geom.LineString) {//线
// geometry = "'" + ((org.locationtech.jts.geom.LineString) pro.getValue()).toString() + "'";
// data.put("geom", geometry);
// } else {
// data.put(pro.getName().toString(), pro.getValue());
// }
// }
// System.out.println(data);
// }

} catch (IOException e) {
e.printStackTrace();
}
return featureCollection;
}
//方法一:
//返回其属性值
public List<LinkedHashMap<String,Object>> getAttirbutes(String srs, FeatureCollection col){
//srs="EPSG:4326"
List<LinkedHashMap<String,Object>> listMap = new ArrayList<>();
FeatureIterator<SimpleFeature> iterator = col.features();
while(iterator.hasNext()) {
SimpleFeature feature = iterator.next();
//获取属性
Iterator<Property> it = feature.getProperties().iterator();
LinkedHashMap<String, Object> data = new LinkedHashMap<>();
String geometry = "";
while (it.hasNext()) {
Property pro = it.next();
if (pro.getValue() instanceof Point) {//点
geometry = "'" +((Point) pro.getValue()).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
data.put("geom",geometry);
} else if (pro.getValue() instanceof Polygon) {//面
geometry = "'"+((Polygon) pro.getValue()).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
data.put("geom",geometry);
} else if (pro.getValue() instanceof MultiPolygon) {//多面
geometry = "'"+((MultiPolygon) pro.getValue()).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
data.put("geom",geometry);
} else if (pro.getValue() instanceof LineString) {//线
geometry = "'" +((LineString) pro.getValue()).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
data.put("geom",geometry);
} else {
if(pro.getValue() instanceof Date){
Date myDate = (Date)pro.getValue();
SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String strDate3 = sdf3.format(myDate);
data.put(pro.getName().toString(),strDate3);
}else{
data.put(pro.getName().toString(),pro.getValue());
}
}
}
//System.out.println(data);
listMap.add(data);
}
return listMap;
}
//方法二:
//返回属性值
public List<LinkedHashMap<String,Object>> getAttirbutes2(String srs, FeatureCollection col){
//srs="EPSG:4326"
List<LinkedHashMap<String,Object>> listMap = new ArrayList<>();
//另外一种循环start
SimpleFeatureCollection sfc = (SimpleFeatureCollection)col;
// 获取当前矢量数据有哪些属性字段值
List<AttributeDescriptor> attributes = sfc.getSchema().getAttributeDescriptors();
// 拿到迭代器
SimpleFeatureIterator simpleFeatureIterator = sfc.features();
// 遍历每一个要素
while(simpleFeatureIterator.hasNext()) {
SimpleFeature simpleFeature = simpleFeatureIterator.next();
LinkedHashMap<String, Object> data = new LinkedHashMap<>();
// java8新特性流api
attributes.stream().forEach((a) -> {
Object tempobj = simpleFeature.getAttribute(a.getLocalName());
// 依次读取这个shape中每一个属性值,当然这个属性值,可以处理其它业务
if(a.getLocalName().indexOf("geom")>=0){
String geometry = "";
if (tempobj instanceof Point) {//点
geometry = "'" +((Point) tempobj).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
data.put("geom",geometry);
} else if (tempobj instanceof Polygon) {//面
geometry = "'"+((Polygon) tempobj).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
data.put("geom",geometry);
} else if (tempobj instanceof MultiPolygon) {//多面
geometry = "'"+((MultiPolygon) tempobj).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
data.put("geom",geometry);
} else if (tempobj instanceof LineString) {//线
geometry = "'" +((LineString) tempobj).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
data.put("geom",geometry);
}
}else{
if(tempobj instanceof Date){
Date myDate = (Date)tempobj;
SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String strDate3 = sdf3.format(myDate);
data.put(a.getLocalName(),strDate3);
}else{
data.put(a.getLocalName(),tempobj);
}
// System.out.println(a.getLocalName() + ":" + simpleFeature.getAttribute(a.getLocalName()));
}
});
listMap.add(data);
}
return listMap;
}
//查询 CQL
public Filter ReturnFilter(String sql)throws Exception{
String wkt = "POLYGON ((113.17574362102584 23.135924459989738, 113.07445367113468 22.981863911800943, 113.3121749821035 22.932375044753726, 113.3907263718155 23.073180341529934, 113.17574362102584 23.135924459989738))";
Filter filter = null;
// 相交
filter = CQL.toFilter( "OBJECTID = 5 or INTERSECTS(the_geom," + wkt + ")");
if(sql!=null || sql!=""){
filter = CQL.toFilter(sql);
}
// 在10公里以内
// Filter filter = CQL.toFilter( "DWITHIN(the_geom," + wkt + ", 10, kilometers)");
return filter;
}
//查询 使用openGIS FilterFactory2
public Filter ReturnFilter2(){
Filter filter = ff.greaterOrEqual(ff.property("OBJECTID"), ff.literal(5));
return filter;
}

public static SimpleFeatureType createType(Class<?> c, String layerName) {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setCRS(DefaultGeographicCRS.WGS84);
builder.add("FID",String.class);
builder.add("the_geom", c);
// 设置了图层的名字
builder.setName(layerName);
SimpleFeatureType simpleFeatureType = builder.buildFeatureType();
return simpleFeatureType;
}
  //生成shp
public static void createShp(String shpPath, SimpleFeatureCollection collection) throws IOException {
File shpFile = new File(shpPath);
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
SimpleFeatureType simpleFeatureType = collection.getSchema();
// 创造shpstore需要的参数
Map<String, Serializable> params = new HashMap<>();
params.put("url", shpFile.toURI().toURL());
params.put("create spatial index", Boolean.TRUE);
ShapefileDataStore newDataStore =
(ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
newDataStore.createSchema(simpleFeatureType);
Transaction transaction = new DefaultTransaction("create");
String typeName = newDataStore.getTypeNames()[0];
SimpleFeatureSource featureSource = newDataStore.getFeatureSource(typeName);
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
featureStore.setTransaction(transaction);
featureStore.addFeatures(collection);
featureStore.setTransaction(transaction);
transaction.commit();
transaction.close();
}
/  //这里也是读取shp
public static SimpleFeatureCollection readFeatureCollection(String shpPath) {
SimpleFeatureCollection featureCollection = null;
File shpFile = new File(shpPath);
try {
ShapefileDataStore shapefileDataStore = new ShapefileDataStore(shpFile.toURI().toURL());
// 设置编码,防止属性的中文字符出现乱码
shapefileDataStore.setCharset(Charset.forName("UTF-8"));
// 这个typeNamae不传递,默认是文件名称
FeatureSource featuresource = shapefileDataStore.getFeatureSource(shapefileDataStore.getTypeNames()[0]);
featureCollection = (SimpleFeatureCollection) featuresource.getFeatures();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return featureCollection;
}

}

在测试类,测试

@Autowired
    GeoToolsMethod geoToolsMethod;

//测试geoTools封装好的方法
    @Test
    public void Test_geoToolsMethod() throws Exception{
        //测试读取shp
        FeatureSource<SimpleFeatureType, SimpleFeature> featureSource=geoToolsMethod.ReadShpFile("D:\\ceshi\\dwq0606");
        String srs = CRS.lookupIdentifier(featureSource.getSchema().getCoordinateReferenceSystem(),true);  // 获取EPSG
        System.out.println(srs);
        FeatureCollection collection = featureSource.getFeatures();
        long startTime = System.currentTimeMillis();
        //测试获取getAttributes
        List<LinkedHashMap<String,Object>> listAttr = geoToolsMethod.getAttirbutes(srs,collection);
        long endTime = System.currentTimeMillis();
        System.out.println("运行时长:"+(endTime-startTime)+"ms"); //1128ms
        startTime = System.currentTimeMillis();
        //测试获取getAttributes2
        List<LinkedHashMap<String,Object>> listAttr2 = geoToolsMethod.getAttirbutes2(srs,collection);
        endTime = System.currentTimeMillis();
        System.out.println("运行时长:"+(endTime-startTime)+"ms"); //980ms 1015
        //System.out.println(listAttr);
    }
View Code

 

geotools做geometry 的计算距离,取交集、合并几何、difference

//做geometry 的计算距离,取交集、合并几何、difference
    @Test
    public void GeometryOperate() throws Exception{
        GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
        //创建一条线
        List<Coordinate> points1 = new ArrayList<Coordinate>();
        points1.add(new Coordinate(0,0));
        points1.add(new Coordinate(1,3));
        points1.add(new Coordinate(2,3));
        Coordinate[] coords  = (Coordinate[]) points1.toArray(new Coordinate[points1.size()]);
        LineString line1 = geometryFactory.createLineString(coords);
        //创建第二条线
        List<Coordinate> points2 = new ArrayList<Coordinate>();
        points2.add(new Coordinate(3,0));
        points2.add(new Coordinate(3,3));
        points2.add(new Coordinate(5,6));
        Coordinate[] coords2  = (Coordinate[]) points2.toArray(new Coordinate[points2.size()]);
        LineString line2 = geometryFactory.createLineString(coords2);
//        返回(A)与(B)中距离最近的两个点的距离
        System.out.println(line1.distance(line2));//out 1.0
//        两个几何对象的交集
        System.out.println(line1.intersection(line2));//out GEOMETRYCOLLECTION EMPTY
//        几何对象合并
        Geometry lineunion = line1.union(line2);
        System.out.println(lineunion); //out MULTILINESTRING ((0 0, 1 3, 2 3), (3 0, 3 3, 5 6))
        //在A几何对象中有的,但是B几何对象中没有
        System.out.println(line1.difference(line2));//out LINESTRING (0 0, 1 3, 2 3)
        System.out.println(lineunion.difference(line2));//out LINESTRING (0 0, 1 3, 2 3)
        //交集
        System.out.println(lineunion.intersection(line2));//out MULTILINESTRING ((3 0, 3 3), (3 3, 5 6))

        WKTReader reader = new WKTReader(geometryFactory);
        Polygon geometry1 = (Polygon) reader.read("POLYGON((0 0, 2 0 ,2 2, 0 2,0 0))");
        Polygon geometry2 = (Polygon) reader.read("POLYGON((0 0, 4 0 , 4 1, 0 1, 0 0))");
        OverlayOp op = new OverlayOp(geometry1,geometry2);
        Geometry g =op.getResultGeometry(OverlayOp.INTERSECTION);//POLYGON ((2 0, 0 0, 0 1, 2 1, 2 0))
        //Geometry g2 = op.getResultGeometry(OverlayOp.UNION);
        //Geometry g3 = op.getResultGeometry(OverlayOp.DIFFERENCE);
        //Geometry g4 = op.getResultGeometry(OverlayOp.SYMDIFFERENCE);
        //PlanarGraph p = op.getGraph(); //图<v,e

        //LineMerger 线路合并,线路之间不能有交点,并且只在线路末尾有公共交点
        // lineMerger 和union区别,union可以在两条相交的线中生成交点(noded)
        WKTReader wktReader = new WKTReader();
        LineMerger lineMerger = new LineMerger();
        List<Geometry> list = new ArrayList<Geometry>();
        list.add(wktReader.read("LINESTRING (3 3,2 2,0 0)"));
        list.add(wktReader.read("LINESTRING (3 3,6 6,0 10)"));
        list.add(wktReader.read("LINESTRING (0 10,3 1,10 1)"));
        lineMerger.add(list);
        Collection<Geometry> mergerLineStrings = lineMerger.getMergedLineStrings();
        for (Geometry tempg : mergerLineStrings) {
            System.out.println(tempg.toText()); //LINESTRING (0 0, 2 2, 3 3, 6 6, 0 10, 3 1, 10 1)
        }

    }
View Code

 

 

 

 

 

 

 

 

 

标签:java,org,geom,new,import,data,geotools
From: https://www.cnblogs.com/hjyjack9563-bk/p/17517106.html

相关文章

  • java工具类static静态方法读取yml配置
    当我们需要在工具类中获取yml配置的时候,由于变量是staic导致获取不到yml配置因为spring加载静态方法比IOC早,所以不能直接使用@Value注解读取yml配置,读取结果是null。@ComponentpublicclassTestUtil{//使用@Value注解读取yml配置的数据@Value("${test.url}")......
  • 【大厂面试必问】Java8 新特性
    博主介绍:✌博主从事应用安全和大数据领域,有8年研发经验,5年面试官经验,Java技术专家,WEB架构师,阿里云专家博主,华为云云享专家✌......
  • java限流-基于redis+lua
    redis是线程安全的,天然具有线程安全的特性,支持原子性操作,限流服务不仅需要承接超高QPS,还要保证限流逻辑的执行层面具备线程安全的特性,利用Redis这些特性做限流,既能保证线程安全,也能保证性能。结合上面的流程图,这里梳理出一个整体的实现思路:编写lua脚本,指定入参的限流规则,比如对......
  • javascript现代编程系列教程之X——javascript人工智能
    JavaScript在人工智能(AI)领域的应用主要体现在以下几个方面:浏览器端的机器学习:TensorFlow.js是一个在浏览器中运行的JavaScript机器学习库,它允许开发者训练和部署机器学习模型。这使得开发者可以在浏览器端进行实时的机器学习任务,无需将数据传输到服务器端,从而提高了用户的隐......
  • (一)Java中的IO操作—— File类
    一、File类在系统中用户通过文件系统所提供的系统调用实施对文件的操作。最基本的文件操作有:创建文件、删除文件、读文件、写文件、截断文件和设置文件的读/写位置。在Java中使用File类来作为目录或者文件的表示形式,也就是说我们想要表示一个文件,构造一个File对象即可。构......
  • java限流-基于基于guava实现
     1、引入guava依赖<dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>23.0</version></dependency>2、自定义限流注解自定义一个限流用的注解,后面在需要限流的方法或接口上面只需添加该注解即可; importjava......
  • java8 日期、时间处理类
    一、LocalDate类创建LocalDate方法说明staticLocalDatenow()获取默认时区的当前日期,默认返回格式yyyy-MM-ddstaticLocalDatenow(Clockclock)从指定时钟获取当前日期staticLocalDatenow(ZoneIdzone)获取指定时区的当前日期staticLocalDateof(i......
  • 【四】JavaScript之类型转换
    【四】JavaScript之类型转换【1】类型转换javascript是弱类型的编程语言所以本身不仅提供了数据类型的转换甚至在数据使用运算符的时候,javascript的解释器也会出现默认隐式转换数据类型的情况。【2】字符串字符串转换成布尔值除了空字符串("")被转为false,其他的任......
  • 【三】JavaScript之数据类型
    【三】JavaScript之数据类型【0】数据类型展示javascript中变量的值有不同的作用或者功能。按不同的功能,值也可以区分不同的类型。类型名称描述Number数值型整数,浮点数。。。。String字符串文本,一般使用"双引号",'单引号'或者反引号圈起来的都是文本。Bo......
  • 【十】JavaScript之内置对象
    【十】JavaScript之内置对象【1】内置对象build-inObject,也叫内建对象,由浏览器提供给开发者直接使用的。文档地址:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects【2】Number数值对象,在js中一切的数值类型数据,都附带Number对象的......