hi,
post your code plz.
post at least the file opening code.
the following code works (also in a jar) fine for every input file:
public static void main(String[] args) {
String file;
file = System.getProperty("INPUT_FILE");
if (file == null) {
System.out.println("Input File error");
System.exit(-1);
}
try {
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
run command:
java -DINPUT_FILE="C:/Documents and Settings/XXX/My documents/text.txt" -jar myjar.jar
Sorry for my bad explanation and thank you for answering.
I use a fileChooser, this is the code:
fc = new JFileChooser();
int returnVal = fc.showOpenDialog(MiFrame.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
try {
MyClass aux = new MyClass();
aux.processFile(file);
} catch (SAXException e1) {
e1.printStackTrace();
}
}
And in MyClass the method processFile goes like this:
public void processFile(File file) throws SAXException{
try {
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.setContentHandler(new MyHandler(instances));
parser.parse(file.toString());
} catch (Exception e) {
e.printStackTrace();
System.out.println("error: " + e.getMessage());
}
}
>public void processFile(File file) throws SAXException{
> try {
>XMLReader parser = XMLReaderFactory.createXMLReader();
>parser.setContentHandler(new MyHandler(instances));
>parser.parse(file.toString());
> } catch (Exception e) {
>e.printStackTrace();
>System.out.println("error: " + e.getMessage());
> }
>}
What's this: parser.parse(file.toString());
Try this : parser.parse(new InputSource(new FileInputStream(file)));
instead.
Hope That Helps