gpt4 book ai didi

java - 如何更改 java Path 对象的值?

转载 作者:行者123 更新时间:2023-12-02 08:54:42 25 4
gpt4 key购买 nike

下面,我尝试使用 setSoundPath() 方法更改 Path 对象的值那里。我找不到任何文档表明这是可能的。

我正在尝试创建一个类,该类将在指定路径创建文件的副本并将该副本放入指定的文件夹中。不过,我需要能够更改路径的名称,因为我想使用初始占位符文件路径创建声音对象。

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.io.IOException;
import javafx.beans.property.StringProperty;
import javafx.beans.property.SimpleStringProperty;

class Scratch {

public static class Sound extends Object{

private Path there;
StringProperty tests = new SimpleStringProperty(this, "test", "");

public Sound(){
this.there = Paths.get("C:\\Users\\HNS1Lab.NETWORK\\Videos\\JuiceWRLD.mp3");
}

public void setSoundPath(String SoundPath) {
this.tests.setValue(SoundPath);
this.there = Paths.get(this.tests.toString());
}
}

public static void main(String[] args) {
Sound test = new Sound();

test.setSoundPath("C:\\Users\\HNS1Lab.NETWORK\\Music\\Meowing-cat-sound.mp3");
test.copySound();
System.out.println("Path: " + test.getSoundPath().toString());
}

}

最佳答案

他们是immutable :

Implementations of this interface are immutable and safe for use by multiple concurrent threads.

(来自:https://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html)

您可以创建指向您的路径的新 Path 对象。

关于java - 如何更改 java Path 对象的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60555094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com