Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用java将字符串值传递给特定的批处理文件代码段_Java_Batch File_Cmd - Fatal编程技术网

使用java将字符串值传递给特定的批处理文件代码段

使用java将字符串值传递给特定的批处理文件代码段,java,batch-file,cmd,Java,Batch File,Cmd,我试图在批处理文件代码中的特定部分中保存字符串值。但我还不能解决它 这是一段java代码:- Button button = new Button("Click"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileNameExtensionFilter filter = new

我试图在批处理文件代码中的特定部分中保存字符串值。但我还不能解决它

这是一段java代码:-

Button button = new Button("Click");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                FileNameExtensionFilter filter = new FileNameExtensionFilter("CSV File","csv");
                JFileChooser chooser = new JFileChooser("");
                chooser.setAcceptAllFileFilterUsed(false);
                chooser.setDialogTitle("Choose");
                chooser.setFileFilter(filter);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                int returnVal = chooser.showOpenDialog((java.awt.Component) null);
                if ( returnVal == chooser.APPROVE_OPTION ) {
                    textField.setText(chooser.getSelectedFile().toString());

                    String startfile="";
                    Scanner scan = new Scanner(startfile);

                  final JFrame msgframe= new JFrame();
                      msgframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                      startfile=textField.getText(); 
                      JOptionPane.showMessageDialog(chooser, startfile);

                   String outFile = startfile.substring(0, startfile.length()-".csv".length())+".xml"; 
我正在使用选择器选择文件路径,并将其存储在字符串中

现在我需要传递字符串,即“输出文件”到批处理代码的特定部分

批处理文件代码:-

@echo off
start java -jar D:\\xsd\fri.jar "C:/users/.../.../ddd.xml" > C:\Users\...\...\...\sdsd.txt
close
对批处理文件中
中的特定部分进行更改的方法是什么?我有一个按钮,每次单击它时,都会在choose文件的同一目录中创建一个XML文件


中,
存储XML文件

如果我理解了这个问题,您需要读入批处理文件,处理字符串,然后再写出来。@SteveSmith您能告诉我如何使用java处理批处理文件字符串吗。。与批处理命令没有太多交互。如果我没记错的话,您可以在批处理文件中声明
“%~1”
,而不是常量字符串,并使用作为(引用的)命令行参数提供的实际路径运行批处理文件…批处理文件应包含
start”“java-jar D:\\xsd\fri.jar”%~1>C:\Users\…\…\sdsd.txt
,批处理文件是用一个参数调用的,比如
batch-file.bat“C:/users/../…/ddd.xml”
。顺便说一句,批处理文件中没有
close
命令,可能你的意思是
exit/B
,但在这里它是多余的……批处理文件中的
%~1
部分被解析并扩展为(替换为)在执行所有操作之前,它的实际值是
C:/users/../…/ddd.xml
,因此Java接收解析的路径,而不是从字面上接收
%~1
。。。