본문 바로가기

컴퓨터/안드로이드

안드로이드 - 파일카피 예제

package com.copytest;

import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileCopy {
 안드로이드 - 파일카피 예제
 public static String read( String source ) throws Exception
 {
  FileInputStream input = new FileInputStream( source ) ;
  long size = input.available( ) ;
  byte buff[ ] = new byte[ (int)size ] ;
  input.read( buff ) ;
  input.close( ) ;
  return( new String( buff ) ) ;
 }
 
 public static void save( String content ) throws Exception
 {
  FileOutputStream output = new FileOutputStream( "C:/cho.txt" ) ;
  output.write( content.getBytes( ) ) ;
  output.flush( ) ;
  output.close( ) ;
 }

 public static void main(String[] args)
 {
  try
  {
   String content = FileCopy.read( "C:/test.txt" ) ;
   FileCopy.save( content ) ;
  }
  catch( Exception e )
  {
   e.printStackTrace( ) ;
  }
 }
}