home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / documentation / tutorial / networking / security / example / SecurityManagerTest.java < prev   
Encoding:
Java Source  |  1997-07-13  |  1.7 KB  |  44 lines

  1. /*
  2.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "copyright.html"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  */
  17. import java.io.*;
  18.  
  19. import java.io.*;
  20.  
  21. class SecurityManagerTest {
  22.     public static void main(String[] args) {
  23.         try {
  24.             System.setSecurityManager(new PasswordSecurityManager("Booga Booga"));
  25.         } catch (SecurityException se) {
  26.             System.err.println("SecurityManager already set!");
  27.         }
  28.  
  29.         try {
  30.             DataInputStream fis = new DataInputStream(new FileInputStream("inputtext.txt"));
  31.             DataOutputStream fos = new DataOutputStream(new FileOutputStream("outputtext.txt"));
  32.             String inputString;
  33.             while ((inputString = fis.readLine()) != null) {
  34.                 fos.writeBytes(inputString);
  35.                 fos.writeByte('\n');
  36.             }
  37.             fis.close();
  38.             fos.close();
  39.         } catch (IOException ioe) {
  40.             System.err.println("I/O failed for SecurityManagerTest.");
  41.         }
  42.     }
  43. }
  44.