android函数未定义,android – OpenFileOutput()方法未定义!

首先,我在主要活动中编写了一些方法,但我决定他们应该是一个类.

这是我的代码… openFileOutput和openFileInput是未定义的.任何想法??也许应该是服务或活动?

package spexco.hus.system;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.util.Date;

import spexco.hus.cepvizyon.CepVizyon;

import android.content.Context;

public class LicenseIDB {

private String PHONECODEFILE = "CepVizyonCode";

private static String PhoneCode = null;

public LicenseIDB() {

if (readLocal(PHONECODEFILE, 8) == null)

createSystemCode();

}

public static long getDate() {

Date currentTime = new Date();

return currentTime.getTime();

}

public void createSystemCode() {

long date = getDate();

String str = Integer.toHexString(Integer.MAX_VALUE - (int) date);

for (int i = str.length(); i < 8; i++) {

str += "" + i;

}

PhoneCode = str.substring(0, 8);

saveLocal(PhoneCode, PHONECODEFILE);

}

public static String getPhoneCode() {

return PhoneCode;

}

public void saveLocal(String fileString, String Adress) {

try {

FileOutputStream fos = openFileOutput(Adress, Context.MODE_PRIVATE);

fos.write(fileString.getBytes());

fos.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public String readLocal(String Adress, int lenght) {

byte[] buffer = new byte[lenght];

String str = new String();

try {

FileInputStream fis = openFileInput(Adress);

fis.read(buffer);

fis.close();

str = new String(buffer);

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return str;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值