Guava(Resources用法) 读取 classpath 中的文件、读取HTTP

 

假设 classpath 中有个文件是: hello.txt

guava 读取其中的文件内容:

URL url = Resources.getResource("hello.txt");
List<String> lines = Resources.asCharSource(url, Charsets.UTF_8).readLines();

 读取 http://www.iteye.com/ 的内容:

URL url = new URL("http://www.iteye.com/");
List<String> lines = Resources.asCharSource(url, Charsets.UTF_8).readLines();

 

 

下面是 Guava 中Resources的官网 API。

==============

 

com.google.common.io

Class Resources



  • @Beta
     @GwtIncompatible
    public final class Resources
    extends Object
    Provides utility methods for working with resources in the classpath. Note that even though these methods use  URL parameters, they are usually not appropriate for HTTP or other non-classpath resources.

    All method parameters must be non-null unless documented otherwise.

    Since:
    1.0
    Author:
    Chris Nokleberg, Ben Yu, Colin Decker
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
读取LAS文件,需要使用LAS Java工具包。这个工具包提供了一个LASReader类,可以读取LAS文件的数据。以下是一个简单的示例代码: ``` import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import org.geolatte.geom.G2D; import org.geolatte.geom.Point; import org.geolatte.geom.builder.DSL; import org.geolatte.geom.builder.PointBuilder; import java.io.File; import java.io.IOException; import java.util.List; import org.geolatte.geom.builder.DSL; import org.geolatte.geom.builder.GeometryBuilder; import org.geolatte.geom.crs.CoordinateReferenceSystems; import org.geolatte.geom.crs.CrsId; import org.geolatte.geom.jts.JTS; import com.google.common.collect.Lists; import com.google.common.primitives.Floats; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import las.LASHeader; import las.LASReader; public class ReadLasFile { public static void main(String[] args) throws IOException { // 读取LAS文件 LASReader reader = new LASReader(new File("example.las")); LASHeader header = reader.getHeader(); // 获取点云数据 List<double[]> pointCloud = reader.readPointCloud(); // 将点云数据转换为Point对象 List<Point<G2D>> points = Lists.newArrayList(); for (double[] point : pointCloud) { PointBuilder<G2D> builder = DSL.point(); builder.coordinate(DSL.g(2).p(point[0], point[1])); Point<G2D> p = builder.build(); points.add(p); } // 创建多边形对象 GeometryBuilder<G2D> builder = DSL.geometry(CoordinateReferenceSystems.PROJECTED_2D_METER); builder.polygon(DSL.linearRing(points.toArray(new Point[points.size()]))); Geometry<G2D> polygon = builder.build(); // 将多边形对象转换为JSON字符串 JsonObject json = new JsonObject(); json.put("type", "Feature"); json.put("geometry", JTS.toGeoJson(polygon)); System.out.println(json.toString()); } } ``` 这个示例代码读取了一个名为"example.las"的LAS文件,并将其转换为多边形对象。该代码使用了LAS Java工具包、Apache Commons Math、Geolatte Geometry和Guava库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值