This site requires JavaScript, please enable it in your browser!
Greenfoot back
ronald
ronald wrote ...

2021/12/8

FileNotFoundException - Eclipse

ronald ronald

2021/12/8

#
java.io.FileNotFoundException: sounds (Accès refusé) at java.base/java.io.FileInputStream.open0(Native Method) at java.base/java.io.FileInputStream.open(FileInputStream.java:216) at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157) at java.desktop/com.sun.media.sound.SunFileReader.getAudioInputStream(SunFileReader.java:117) at java.desktop/javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1062) at JProgressBarTest03.actionPerformed(JProgressBarTest03.java:69) at JProgressBarTest03.lambda$0(JProgressBarTest03.java:58) at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972) at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2313) at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405) at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262) at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279) at java.desktop/java.awt.Component.processMouseEvent(Component.java:6626) at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3389) at java.desktop/java.awt.Component.processEvent(Component.java:6391) at java.desktop/java.awt.Container.processEvent(Container.java:2266) at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5001) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833) at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948) at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575) at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516) at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310) at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780) at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97) at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:746) at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:744) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90) Hello I am working on a project with Eclipse I can't understand why I can't access my sounds folder can you tell me all the possible causes of FileNotFoundException - access denied ??? thank you for your understanding
danpost danpost

2021/12/8

#
Show relevant codes.
ronald ronald

2021/12/8

#
public static void actionPerformed(ActionEvent ae) throws IOException, UnsupportedAudioFileException, LineUnavailableException  {
		
				try(AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file)) {
					for (int i = 0; i < buttons.length; i++) {
						if (ae.getSource() == buttons[i]) {
							Clip clip = AudioSystem.getClip();
							clip.open(audioInputStream);
							long millis = clip.getMicrosecondLength() / 1000L;
							System.out.println("Playing : " + file.getPath() + " seconds : " + (millis/1000));            
							clip.start();
	                        
							try {
	         
								while(i <= 100) {										
									Thread.sleep((millis/1000)*10);
									jpb.paintImmediately(0, 0, 200, 25);
									jpb.setValue(i);
									i++;                   
								}
							} catch(InterruptedException ie) {
								ie.printStackTrace();
							}
							clip.close();
						}
					}
				}
			}		
		}
I will give you a piece of code, I hope it comes from there
danpost danpost

2021/12/8

#
Here is what is said about that error for the FileInputStream constructors:
If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a FileNotFoundException is thrown.
The file appears to be located, but access is problematic. Check the properties of the file itself. Maybe there is something you can fix there.
ronald ronald

2021/12/8

#
excuse me for bothering you, I think I'm wrong, this piece of code is working I had time to think about my error, I modified my project several times and I wanted to forget some coded pieces like listFiles or isdirectory whereas it is very important to put them to locate the directory I think it comes from tell me please where did you see this sentence? which API? thank you
danpost wrote...
If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a FileNotFoundException is thrown.
danpost danpost

2021/12/9

#
ronald wrote...
where did you see this sentence? which API?
danpost wrote...
If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a FileNotFoundException is thrown.
FileOutputStream-java.io.File
You need to login to post a reply.