0
我想将另一个类中的选定文件插入其他类中,方法doit()
中的变量in
在中。 我怎样才能插入方法度特(),在类元素,而不是此文件“d:\ Probe.txt”,将选中的文件插入FileReader
public void doit() {
try {
in = new BufferedReader(new FileReader("D:\\Probe.txt"));
out = new StreamResult("D:\\data.xml");
initXML();
String str;
while ((str = in.readLine()) != null) {
process(str);
}
in.close();
closeXML();
} catch (Exception e) {
e.printStackTrace();
}
}
值得注意的是这个文件,在从类对话框patch
变量, '
if (cmd.equals("Quelldatei auswählen")) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int ret = fileChooser.showDialog(this, "auswählen");
if (ret == JFileChooser.APPROVE_OPTION) {
File patch = fileChooser.getSelectedFile();
contentPane.add(new JLabel("Quelldatei ist: " + patch));
}
谢谢你的回答,但它必须使用BufferedReader – user2994149
oh..then试试这个:'public void doit(String path){in = new BufferedReader(new FileReader(path));}' –
你明白了吗,我想分配一个选定的文件在来自Element类的“in”变量中,从Dialog类到FileReader的“patch”变量 – user2994149