2024年3月10日18:30:23

master
zm 2024-03-10 19:06:30 +08:00
parent 5dae0c8443
commit b471abf543
4 changed files with 46 additions and 15 deletions

3
minio.properties Normal file
View File

@ -0,0 +1,3 @@
endpoint = http://192.168.1.254:9000
accessKey = minioadmin
secretKey = minioadmin

View File

@ -3,6 +3,7 @@ package com.zhangmeng.minio.controller;
import com.zhangmeng.minio.model.BucketFile;
import com.zhangmeng.minio.utils.AlertUtils;
import com.zhangmeng.minio.utils.MinioUtils;
import com.zhangmeng.minio.utils.ResourceUtils;
import io.minio.messages.Bucket;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
@ -143,15 +144,14 @@ public class MinioController {
ObservableMap<String, Object> namespace = fxmlLoader.getNamespace();
TextArea text_area = (TextArea) namespace.get("text_area");
Button save_p = (Button) namespace.get("save_p");
URL resource = this.getClass().getResource("/minio.properties");
fileInputStream = new FileInputStream(new File(resource.getFile()));
fileInputStream = new FileInputStream(ResourceUtils.getPropertiesFile());
byte[] bytes = fileInputStream.readAllBytes();
text_area.setText(new String(bytes, StandardCharsets.UTF_8));
Stage stage = AlertUtils.alert("minio 配置文件",root,600,410,(Stage) MinioUtils.objectMap.get(MinioUtils.primaryStage));
save_p.setOnAction(event1 -> {
stage.close();
try {
FileWriter fileWriter = new FileWriter(resource.getFile());
FileWriter fileWriter = new FileWriter(ResourceUtils.getPropertiesFile());
fileWriter.write(text_area.getText());
fileWriter.flush();
fileWriter.close();
@ -263,14 +263,13 @@ public class MinioController {
// 创建一个Properties对象
Properties properties = new Properties();
URL resource = this.getClass().getResource("/minio.properties");
if (resource != null){
File file = ResourceUtils.getPropertiesFile();
if (file != null){
InputStream input = null;
OutputStream output = null;
try {
String file = resource.getFile();
input = new FileInputStream(new File(file));
output = new FileOutputStream(new File(file));
input = new FileInputStream(file);
output = new FileOutputStream(file);
// load a properties file
properties.load(input);
properties.put("endpoint",this.endpoint.getText());
@ -302,12 +301,11 @@ public class MinioController {
public void load_property(){
Properties prop = new Properties();
URL resource = this.getClass().getResource("/minio.properties");
if (resource != null){
String file = resource.getFile();
File file = ResourceUtils.getPropertiesFile();
if (file != null){
InputStream input = null;
try {
input = new FileInputStream(new File(file));
input = new FileInputStream(file);
// load a properties file
prop.load(input);
// get the property value and print it out

View File

@ -32,9 +32,7 @@ public class MinioUtils {
private static MinioClient minioClient = null;
// private static String endpoint = "http://192.168.1.254:9000";
// private static String accessKey = "minioadmin";
// private static String secretKey = "minioadmin";
public static Map<String,Object> objectMap = new HashMap<>();
public static String current_bucket = "current_bucket";

View File

@ -0,0 +1,32 @@
package com.zhangmeng.minio.utils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
/**
* @author zhangmeng
* @version 1.0
* @date 2024-03-10 18:49
*/
public class ResourceUtils {
/**
* Properties prop = new Properties();
* URL resource = this.getClass().getResource("/minio.properties");
*/
public static File getPropertiesFile(){
String file_path = System.getProperty("user.dir") + "/minio.properties";
File file = new File(file_path);
if (!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}
}