Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
selectedFile = selectedFile.toString().replace("\\" ,"/");
if (result == JFileChooser.APPROVE_OPTION) {
selectedFile = fileChooser.getSelectedFile();
}
selectedPath = selectedFile.toPath();
String pathString = selectedPath.toString();
pathString = pathString.replaceAll("\\\\","/");
wie wäre es mit File.separator anstatt "\\\\" ?Java:selectedPath = selectedFile.toPath(); String pathString = selectedPath.toString(); [CODE=java]pathString = pathString.replaceAll(File.separator,"/");
pathString = pathString.replaceAll(File.separator,"/");
Das wird nicht funktionieren, da replaceAll ein Regulären Ausdruck erwartet und da ist der \ auch wieder nur ein escape Zeichen. Daher ja die zweite Verdoppelung.wie wäre es mit File.separator anstatt "\\\\" ?
Code:pathString = pathString.replaceAll(File.separator,"/");
Doch!Das wird nicht funktionieren, da replaceAll ein Regulären Ausdruck...
public class Main {
public static void main(String[] args) {
String path = "/usr/bin/java";
String tmp = path.replaceAll(java.io.File.separator, "|");
System.out.println(path+"\n"+tmp);
}
}
Die Problematik tritt nicht bei Unix Trenner auf sondern nur bei dem Windows Trenner, denn dort ist dieser ist der Backslash und der hat in regulären Ausdrücken eine besondere Bedeutung. Probiere es also einfach unter Windows aus. Oder glaube @Robertop, der darauf schon in #2 hingewiesen hat.
Die JVM ist schon gleich. Das Problem ist hier lediglich, dass File.separator ein Zeichen sein kann, dass in Regulären Ausdrücken eine besondere Bedeutung haben kann. Das ist bei Windows z.B. der Fall, denn dort ist das Zeichen hat der Backslash und der ist in regulären Ausdrücken auch das Escape Zeichen. Daher bräuchte man in dem regulären Ausdruck zwei davon. Und das macht dann in einem String Literal 4 Backslash um eben ein String mit zwei Backslash zu bekommen.Also JVM ist doch nicht immer gleich JVM zwischen Linux und Windows? So ist es wahrscheinlich auch mit dem Problem
Das geht auch bei WindowsDie Problematik tritt nicht bei Unix Trenner auf sondern nur bei dem Windows Trenner, denn dort ist dieser ist der Backslash und der hat in regulären Ausdrücken eine besondere Bedeutung. Probiere es also einfach unter Windows aus. Oder glaube @Robertop, der darauf schon in #2 hingewiesen hat.
class Scratch {
public static void main(String[] args) {
String path = "C:\\tmp\\test";
String tmp = path.replace(File.separator, "|");
System.out.println(path+"\n"+tmp);
}
}
C:\tmp\test
C:|tmp|test
You scratch my back and I'll scratch your back, huh?🤣 I'm not against IDE like you say, but I don't let IDE rule me and tell me what to do. Maybe you would say that this old Joe is too backward. Nope! Let me tell you this: Self-driving cars are currently en vogue for the wannabe modern. But if you have to work with AI, you will see the limitations of AI. Even the most touted ChatGPT is mocked (as smart as a 6 year old toddler). Google gives its developers a gag order to babble out the "Bard" project (an AI chatbot). Why? Because Bard is more unpredictable than the most spoiled 6-year-old toddler. Back to the IDE/Self-Driving question: Would you rather be backward and take your life in your own hands THAN let AI drive the car and put your life in the hands of an unknown AI bot?Die böse IDE
Ich verstehe die ganze Diskussion nicht. Was hat die Anforderung eigentlich mit String.replaceAll zu tun?Ziel ist es einen Path zu String zu machen
Path path = Path.of("c:", "Dev", "test.json");
System.out.println(path.toString());
Sorry, but I do not understand that.but I don't let IDE rule me and tell me what to do.
🤣Congratulation.The IDE does not tell me, what to do. You can configure it. You the IDE is not telling me what to do but it tells me, when I did something wrong
You are talking about newbies? I was explicitly talking about (professional) software engineers. Just to clarify that point.Have you ever known how desperate newbies were and still are with IDE. Beginning with the downloading and end up with compiler installation.
Darüber, dass eine IDE dich vor dem Fehler mit replaceAll bewahrt hätte allerdings nicht 🙃The Germans used to say "Über Geschmack lässt sich nicht streiten."