Results 1 to 4 of 4
  1. #1
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default Copy single file to another folder

    i got an error here from this code:

    Java Code:
    btnAttach.addSelectionListener(new SelectionAdapter(){
    	public void widgetSelected(SelectionEvent e){
    	dialog= new FileDialog(shellNews,SWT.SAVE);
    	String[] fileExtension ={"*.jpg","*.jpeg"};
    	dialog.setFilterExtensions(fileExtension);
    	String file = dialog.open();
    	dialog.getFileName();
    	if(file!=null)
    		{lbltxt.setText(file);
    		
    		String dest="D:\\systembackup\\sept29\\webportalCMS\\bin\\myPortal\\";
    		
    		File filekoto = new File(file);
    		File destngFile = new File(dest);
    		
    		try {
    			InputStream is = new FileInputStream(filekoto);
    			OutputStream os = new FileOutputStream(destngFile);
    			
    			   byte[] buf = new byte[1024];
    			    int len;
    			    while ((len = is.read(buf)) > 0) {
    			        os.write(buf, 0, len);
    			    }
    			    is.close();
    			    os.close();
    			
    		   boolean ko=filekoto.renameTo(destngFile);
    		   System.out.println(ko);
    		   
    		} catch (FileNotFoundException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    		} catch (IOException eg) {
    			// TODO Auto-generated catch block
    			eg.printStackTrace();
    		}
    	
    		}
    	
    	}
    		
    		
    		
    });
    here is the error:


    java.io.FileNotFoundException: D:\systembackup\sept29\webportalCMS\bin\myPortal (Access is denied)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at webportalcms.NewsModule$1.widgetSelected(NewsModul e.java:78)
    at org.eclipse.swt.widgets.TypedListener.handleEvent( TypedListener.java:234)
    at org.eclipse.swt.widgets.EventTable.sendEvent(Event Table.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.ja va:1053)
    at org.eclipse.swt.widgets.Display.runDeferredEvents( Display.java:4066)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Di splay.java:3657)
    at webportalcms.mainPage.main(mainPage.java:117)

    filenotfoundexception???
    :cool:

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    It said that you had access is denied, You try create new file in a folder, where you have not access.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default

    now i know the problem... i should indicate the new name of the file.. is there other way to copy the file without renaming on it?
    :cool:

  4. #4
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default

    I RESOLVED IT! :) thanks pete for enlighten me... i just get the file name by this

    ...\\"+dialog.getFileName+".jpg";

    thanks:D
    :cool:

Similar Threads

  1. Replies: 5
    Last Post: 12-23-2009, 12:36 PM
  2. Copy a file to a folder.
    By leric in forum New To Java
    Replies: 7
    Last Post: 07-29-2009, 06:11 AM
  3. Replies: 1
    Last Post: 06-23-2008, 07:46 AM
  4. How can i copy a folder from one place to another..
    By rajeshgubba in forum New To Java
    Replies: 4
    Last Post: 06-14-2008, 03:21 AM
  5. java file copy
    By hknyo in forum New To Java
    Replies: 1
    Last Post: 06-12-2008, 05:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •