⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringbyteoperations.java

📁 相册是J2me MIDLet 的一个demo程序
💻 JAVA
字号:
/*
 *  Filename:  StringByteOperations.java
 *  - contains definition of the class StringByteOperations. It has static methods for String-to-Byte and 
 *  Byte-to-String Convertions. 
 *
 *  
 *  Application Name: Image Album Demo 
 *  Version: 2.0
 *  Release Date: 27th September, 2002
 *  Author:	Edmund Wong, Application Engineer, Metrowerks Hong Kong
 *
 *
 *  (c) Copyright. 2002. Metrowerks Corp. ALL RIGHTS RESERVED.
 *	This code is provided "AS IS" without warranty of any kind and subject to Metrowerks Sample Application
 *  End User License Agreement. NO EXTERNAL DISTRIBUTION OR COMMERCIALIZATION OF THE SOFTWARE IS PERMITTED 
 *  EXCEPT BY WRITTEN AGREEMENT OF METROWERKS."
 */


import javax.microedition.io.*;
import java.io.*;



public class StringByteOperations {
	
		
    /**
     *  Constructor for StringByteOperations
     */
     
    public StringByteOperations() {
          
        
    }

    /**
     *  Static method for converting String into Byte Array
     */
     
    public static byte[] stringToByteConvertion(String string) throws Exception{
        
        
        byte[] byteArray = null;    
                                   
 		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
 		
 		DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
 	 		
 		 		 		           
        try {
        
        			dataOutputStream.writeUTF(string);
        	
        			byteArray = byteArrayOutputStream.toByteArray();
        	
        			byteArrayOutputStream.close();
        	
        			dataOutputStream.close();
        	
       	}
        
        catch (Exception e) {
        
        
        }	
        	
        return byteArray;	
						
        }
        
       					
   /**
    *  Static method for converting Byte Array into String
    */  
       
    public static String byteToStringConvertion(byte[] byteArray) throws Exception{
        
        
        String string = null;    
                                   
 		ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
 		
 		DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
 		 		
 		 		 		           
        try {
        
        			string = dataInputStream.readUTF();        	
        			        	
        			byteArrayInputStream.close();
        	
        			dataInputStream.close();
        	
        }
        
        catch (Exception e) {
        
        
        }	
        	
        return string;	
						
        }
        
       		
       	
}

    
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -