import hashlib
import os
def genJavaFile(packageName, soFile):
className, suffix = soFile.split('.');
className = className[0:1].upper() + className[1:]
out_file = open(className + '.java', 'w')
with open(soFile, 'rb') as f:
data_bytes = f.read()
out_file.write('package ' + packageName + ';\n\n')
out_file.write('class ' + className + ' {\n')
out_file.write(' public static String ' + className[0:1].lower() + className[1:] + ' = ')
str = ''
for data_byte in data_bytes:
str += '%02x' % data_byte
m = hashlib.md5()
m.update(str.encode('utf8'))
digest = m.hexdigest()
str = '\"' + str + '\"' + ';\n'
out_file.write(str)
out_file.write(' public static String digest = \"%s\";\n' % digest)
out_file.write('}')
out_file.close()
def genJavaFiles():
for root, dirs, files in os.walk('./'):
for file in files:
if file[-3:] == '.so':
genJavaFile('com.xxx.xxx', file)
genJavaFiles()
文件操作 -- 生成java文件
猜你喜欢
转载自www.cnblogs.com/llh1874/p/9208881.html
今日推荐
周排行