简体   繁体   中英

How do I change the value of a java Path object?

Below, I am trying to change the value of the Path object there using the setSoundPath() method. I cannot find any documentation to say this is possible.

I am trying to create a class that will create a copy of a file at a specified path and put the copy in the specified folder. I need to be able to change the name of the path though, because I want to create the sound object with an initial placeholder file 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());
    }

}

They are immutable :

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

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

You can create new Path objects that point to your path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM