使用Java代码直接操作设备文件来测试Linux驱动 第2页

;
43.        byte[] buffer = new byte[4]; 
44.        try 
45.        { 
46.            //  打开/dev/wordcount设备文件  
47.            FileInputStream fis = new FileInputStream("/dev/wordcount"); 
48.            //  从设备文件中读取4个字节   
49.            fis.read(buffer); 
50.            //  将4个字节转换成int类型的值  
51.            n = ((int) buffer[0]) << 24 | ((int) buffer[1]) << 16 
52.                    | ((int) buffer[2]) << 8 | ((int) buffer[3]);  
53.            fis.close(); 
54.        } 
55.        catch (Exception e) 
56.        { 
57.        } 
58.        return n; 
59.    } 
60.   //  向/dev/wordcount设备文件中写入毕业论文 字符串  
61.    private void writeStringToDev(String str) 
62.    { 
63.        try 
64.        { 
65.            //  打开/dev/wordcount设备文件  
66.            FileOutputStream fos = new FileOutputStream("/dev/wordcount"); 
67.            //  写入字符串  
68.            fos.write(str.getBytes("iso-8859-1")); 
69.            fos.close(); 
70.        } 
71.        catch (Exception e) 
72.        { 
73.        } 
74.    } 
75.} 
package mobile.android.word.count.java;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;

上一页  [1] [2] [3] [4] 下一页

  • 上一篇文章:
  • 下一篇文章:
  • Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有