Results 1 to 19 of 19
Thread: FileInputStream Problems.
- 08-10-2010, 06:44 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 55
- Rep Power
- 0
-
You're doing something wrong, but without code, I'm not sure how we can know why. Please read my signature link about creating and posting an SSCCE.
Last edited by Fubarable; 08-10-2010 at 07:16 PM.
- 08-10-2010, 07:15 PM #3
Member
- Join Date
- Apr 2010
- Posts
- 55
- Rep Power
- 0
Really not much to seeJava Code:private void initComponents(){ MenuItem Open = new MenuItem("فتح ملف"); MenuItem Exit = new MenuItem("خروج"); Menu File = new Menu("ملف"); Menu Edit = new Menu("تعديل"); File.add(Open); File.add(Exit); Open.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){OpenFileDialog dialog = new OpenFileDialog(); javax.swing.JOptionPane.showMessageDialog(dialog, "File Opened"); File file = dialog.chosenFile; FileInputStream stream = new FileInputStream(file);// error here GasWaterRecordsProcessor processor = new GasWaterRecordsProcessor(stream); gwpanel.flipPage(0);} }); Exit.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){System.exit(0);} }); MenuBar bar = new MenuBar(); bar.add(File); bar.add(Edit); super.setMenuBar(bar); Container pane = super.getContentPane(); JTabbedPane tabs = new JTabbedPane(); tabs.add(gwpanel, "الغاز والمياه"); pane.add(tabs); super.setSize(800,470); super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
Most of us do better with an SSCCE. Again, I urge you to read the link. Also helps if we can see the actual error messages.
Luck!
- 08-10-2010, 07:22 PM #5
Member
- Join Date
- Apr 2010
- Posts
- 55
- Rep Power
- 0
I really dont know how much more to tell you. I practically copy pasted from a guide
-
I understand, and what you've posted may be enough for some here to help you, but me, I'm not smart enough, and I do much better if you produce an SSCCE, a small program that we can compile, run, and see your problem first hand, that has no code present unrelated to your problem, and that we can modify to hopefully find a solution. So if no one smarter posts a simple solution, then please read the link. Here it is again:
SSCCE.
Much luck!
- 08-10-2010, 07:27 PM #7
Member
- Join Date
- Apr 2010
- Posts
- 55
- Rep Power
- 0
Oh its a program... I thought it was that how to write a question guide
Hold on..
- 08-10-2010, 07:28 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
What happens when you do this:
kind regards,Java Code:FileInputStream stream = new FileInputStream(file.getAbsolutePath());
Jos
- 08-10-2010, 07:31 PM #9
Member
- Join Date
- Apr 2010
- Posts
- 55
- Rep Power
- 0
Same error: Unreported error at java.io.FileNotFoundException
- 08-10-2010, 07:37 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
- 08-10-2010, 07:39 PM #11
Member
- Join Date
- Apr 2010
- Posts
- 55
- Rep Power
- 0
Thanks Jos ill try that ill let you know
- 08-10-2010, 08:03 PM #12
Member
- Join Date
- Apr 2010
- Posts
- 55
- Rep Power
- 0
Entering the pathname manually renders no exception. only with JFileChooser it does
- 08-10-2010, 08:22 PM #13
If you can execute the program in a command prompt, you could copy the full contents of the screen here.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
- 08-10-2010, 08:22 PM #14
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
- 08-10-2010, 08:27 PM #15
Member
- Join Date
- Apr 2010
- Posts
- 55
- Rep Power
- 0
Im using netbeans ide i dont know i i can use command prompt
@Jos Yes they are identical. I tried the absolute filepath and the relative non worked.
- 08-10-2010, 08:32 PM #16
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,398
- Blog Entries
- 7
- Rep Power
- 17
- 08-10-2010, 08:48 PM #17
Member
- Join Date
- Apr 2010
- Posts
- 55
- Rep Power
- 0
I saw somewhere that it might be open in another process thats why, but i cant see the process, thats why i came here. Anyway thanks for the help guys really appreciate it
- 08-11-2010, 08:56 AM #18
Moderator
- Join Date
- Apr 2009
- Posts
- 10,452
- Rep Power
- 16
How are you handling the FileNotFoundException?
I see no try/catch in your code.
There's usually more information than just the exception name.
For example this code:
gives me this stack trace, which tells me the file name it has attempted to find:Java Code:public class Scratch { public static void main (String[] args) { File f= new File("C:/blah.blh"); FileReader fr = null; try { fr = new FileReader(f); } catch (FileNotFoundException ex) { ex.printStackTrace(); } finally { if (fr != null) { try { fr.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
Java Code:java.io.FileNotFoundException: C:\blah.blh (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:106) at java.io.FileReader.<init>(FileReader.java:55) at Scratch.main(Scratch.java:25)
- 08-11-2010, 11:11 AM #19
Member
- Join Date
- Apr 2010
- Posts
- 55
- Rep Power
- 0
Amazingly it worked. I wanted to avoid try catch because variables in the statement cannot be read outside it. I encapsulated the entire block with try catch and it worked thanks a lot :).
Now to find something that reads arabic excel files.......
For those of you who dont know poi and JExcel support foreign characters only, not orientations. If an excel document was created with an arabic version for excel for example it will give an unreported error in IOException.
Similar Threads
-
FileInputStream not recognising file
By javabarn in forum New To JavaReplies: 3Last Post: 07-08-2010, 09:52 PM -
FileReader Vs FileInputStream and same goes to output
By unhurt in forum New To JavaReplies: 5Last Post: 02-02-2010, 09:06 AM -
FileInputStream
By pachufir in forum New To JavaReplies: 3Last Post: 12-11-2009, 05:07 PM -
FileOutputStream > int > FileInputStream
By dudejonne in forum New To JavaReplies: 11Last Post: 11-11-2009, 04:03 PM -
Empty FileInputStream..
By dudejonne in forum New To JavaReplies: 5Last Post: 11-08-2009, 08:21 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks