加载文件的两种方式

1,文件在具体的包下

ClassLoader loader = this.getClass().getClassLoader();
InputStream is = loader.getResourceAsStream("com\\atguigu\\java\\jdbc.properties");

2,文件在当前工程下

FileInputStream is = new FileInputStream(new File("jdbc1.properties"));

如下图:


 

//法一:
ClassLoader loader = this.getClass().getClassLoader();
InputStream is = loader.getResourceAsStream("com\\atguigu\\java\\jdbc.properties");
//法二:
// FileInputStream is = new FileInputStream(new File("jdbc1.properties"));

Properties pros = new Properties();
pros.load(is);
String name = pros.getProperty("user");
System.out.println(name);

String password = pros.getProperty("password");
System.out.println(password);

转载于:https://www.cnblogs.com/dreamHighMjc/p/7446222.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
QML 3D场景可以通过两种方式进行加载: 1. 直接在QML文件中定义场景。这种方式适用于简单的场景,可以通过使用QML的3D元素(如 Box、Sphere、Cylinder 等)来创建3D模型和场景。 例如,以下代码创建了一个简单的场景,其中包含一个盒子和一个球体: ``` import Qt3D.Core 2.12 import Qt3D.Render 2.12 import Qt3D.Extras 2.12 Entity { id: rootEntity components: [ RenderSettings { activeFrameGraph: ForwardRenderer { clearColor: "transparent" } }, Camera { id: camera projectionType: CameraLens.PerspectiveProjection fieldOfView: 45 aspectRatio: 16/9 nearPlane : 0.1 farPlane : 1000.0 position: Qt.vector3d(0.0, 0.0, 40.0) upVector: Qt.vector3d(0.0, 1.0, 0.0) viewCenter: Qt.vector3d(0.0, 0.0, 0.0) } ] BoxMesh { id: boxMesh width: 5.0 height: 5.0 depth: 5.0 } SphereMesh { id: sphereMesh radius: 2.0 } Transform { id: boxTransform translation: Qt.vector3d(-10.0, 0.0, 0.0) } Transform { id: sphereTransform translation: Qt.vector3d(10.0, 0.0, 0.0) } Material { id: material effect: PhongMaterial { ambient: Qt.rgba(0.1, 0.1, 0.1, 1.0) diffuse: Qt.rgba(1.0, 1.0, 1.0, 1.0) specular: Qt.rgba(0.3, 0.3, 0.3, 1.0) shininess: 100.0 } } PhongMaterial { id: material2 ambient: Qt.rgba(0.1, 0.1, 0.1, 1.0) diffuse: Qt.rgba(1.0, 1.0, 1.0, 1.0) specular: Qt.rgba(0.3, 0.3, 0.3, 1.0) shininess: 100.0 } Entity { id: boxEntity components: [ boxMesh, material, boxTransform ] } Entity { id: sphereEntity components: [ sphereMesh, material2, sphereTransform ] } } ``` 2. 通过使用Qt3DSceneLoader加载外部3D模型文件。这种方式适用于复杂的场景,可以使用专业的3D建模软件(如Blender、Maya等)创建模型和场景,并将其导出为支持Qt3D的格式(如.gltf、.obj等)。 例如,以下代码使用Qt3DSceneLoader加载一个外部的.gltf文件: ``` import Qt3D.Core 2.12 import Qt3D.Render 2.12 import Qt3D.Extras 2.12 Entity { id: rootEntity components: [ RenderSettings { activeFrameGraph: ForwardRenderer { clearColor: "transparent" } }, Camera { id: camera projectionType: CameraLens.PerspectiveProjection fieldOfView: 45 aspectRatio: 16/9 nearPlane : 0.1 farPlane : 1000.0 position: Qt.vector3d(0.0, 0.0, 40.0) upVector: Qt.vector3d(0.0, 1.0, 0.0) viewCenter: Qt.vector3d(0.0, 0.0, 0.0) } ] Entity { id: externalEntity Qt3DSceneLoader { id: loader source: "path/to/external/file.gltf" } onStatusChanged: { if (loader.status === Qt3DRender.Qt3DRender.Loaded) { rootEntity.addComponent(externalEntity) } } } } ``` 以上是两种加载QML 3D场景的方式,您可以根据自己的需求进行选择。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值