close
  • 홈
  • :
  • 위치로그
  • :
  • 태그
  • :
  • 방명록
  • :
  • 관리자
  • :
  • 새글쓰기
블로그 이미지

이슬나라 [isulnara.com]
프로그램 관련 문의...
전체 (208)
자작 프로그램 (24)
EzIP (3)
IEPageSetup (3)
iSysInfoX (2)
메신저 알림이 (1)
ezSVC (1)
WebFTP (2)
iDebugX (1)
기타 (10)
버그 신고 (1)
이것저것.. (55)
WebFTP 게시판 (0)
팁 모음 (77)
linux (21)
프로그래밍 (36)
윈도우 (5)
네크워크 (7)
기타 (7)
윈도우 숨은.. (4)
터미널 서비스.. (1)
공개 웹하드 (1)
관리자 (0)
PC 원격제어.. (1)
NAS (43)
«   2012/02   »
일 월 화 수 목 금 토
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      
ftpls ftplist ftpdir dspack Spin The Bottle bin JDBC proftpd Pixels 안드로이드 atom 리모콘 SFTP DenyHosts 시놀로지 synology 콘솔프로그램 sed utf-8 htpc CRC location.href surveillance 텍스트큐브 WebFTP sms ds107 xbmc rsync FileStation Subversion bash
[ezLink] 동시 접속수...
ezLink 1.2.1.2 정식... (3)
MD5 CRC 체크섬.
Apache, Subversion...
CentOS에 MongoDB 설치.
예.. 제가 직접 만들어서...
isul / 01/29
직접 만드시는 프로그램...
LuckySh / 01/28
109j용 1869가 synology...
isul / 01/22
Ds-109j 1869 가지고 계...
심재규 / 01/21
시도해보지는 않았지만 S...
isul / 01/20
일반 어플리케이션을 서...
ㅇㅇ/ / 2009
사이코웨어 : nProtect,...
√ MIRiyA's AstraLog / 2008
웹페이지에서 인쇄시 머...
醉生夢死™ / 2006
웹페이지에서 MAC Addres...
날자~!! 날어~!! / 2005
 최근글 목록
 2011/11 [2]
 2011/10 [3]
 2011/09 [1]
 2011/07 [3]
 2011/06 [1]
넷하드 - NAS 카페
무료 원격제어 프로그램
블로그가 뭥미?
솔라리스 테크넷
스티브 맥코넬
시놀로지 NAS 카페
하얀나무 - 캠핑 전문 쇼핑몰
하얀나무's Story
Total of
456388 visitors
Today 95
Yesterday 189
 
     
 팁 모음/프로그래밍 
java.io.File.renameTo fails on a NFS mounted location
Posted on 2009/02/26 13:16
 
 
 
 
package some.package;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
* This class contains static methods that perform
operations on files
* Due to limitations of File objects across NFS mounted
filesystems
* this class provides a workaround
*
*/

public final class FileUtils
{
/** Private constructor to prevent instantiation.
* All of the methods of this class are static.
*/
private FileUtils()
{
//prevent instantiation;
}

/** Copy a File
* The renameTo method does not allow action across NFS
mounted filesystems
* this method is the workaround
*
* @param fromFile The existing File
* @param toFile The new File
* @return <code>true</code> if and only if the renaming
succeeded;
* <code>false</code> otherwise
*/
public final static boolean copy (File fromFile, File toFile)
{
try
{
FileInputStream in = new FileInputStream(fromFile);
FileOutputStream out = new FileOutputStream(toFile);
BufferedInputStream inBuffer = new BufferedInputStream
(in);
BufferedOutputStream outBuffer = new
BufferedOutputStream(out);

int theByte = 0;

while ((theByte = inBuffer.read()) > -1)
{
outBuffer.write(theByte);
}

outBuffer.close();
inBuffer.close();
out.close();
in.close();

// cleanupif files are not the same length
if (fromFile.length() != toFile.length())
{
toFile.delete();

return false;
}

return true;
}
catch (IOException e)
{
return false;
}
}

/** Move a File
* The renameTo method does not allow action across NFS
mounted filesystems
* this method is the workaround
*
* @param fromFile The existing File
* @param toFile The new File
* @return <code>true</code> if and only if the renaming
succeeded;
* <code>false</code> otherwise
*/
public final static boolean move (File fromFile, File toFile)
{
if(fromFile.renameTo(toFile))
{
return true;
}

// delete if copy was successful, otherwise move will fail
if (copy(fromFile, toFile))
{
return fromFile.delete();
}

return false;
}
}


http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4073756
Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
이올린에 북마크하기(0) 이올린에 추천하기(0)
Trackback [0] : Comment [0]
TrackbackAddress
http://isulnara.com/tt/trackback/182
SecretComment
  1 ... 58 59 60 61 62 63 64 65 66 ... 208