無標題文章

4.整型或其他類型與字符串類型的相互轉(zhuǎn)換。
int a = Integer.parseInt(String s)

5.寫到文件中:
static private int freqShink(String freqFileName, int freq){
int return_value = -1;
FileInputStream fin = null;
FileWriter writer = null;
File cpu_scaling_file = new File(freqFileName);
try{
fin = new FileInputStream(cpu_scaling_file);
int length = fin.available();
byte [] buffer = new byte[length];
fin.read(buffer);
String res = new String(buffer);
int old_freq = Integer.parseInt(res.trim()); //文件中內(nèi)容讀到byte數(shù)組,轉(zhuǎn)為字符串,再從中轉(zhuǎn)為整型

        writer = new FileWriter(freqFileName);
        writer.write(Integer.toString(freq).toCharArray()); //將整型轉(zhuǎn)為字符串,再轉(zhuǎn)為字符數(shù)組寫到文件中

        if(DEBUG){Log.i(TAG, freqFileName + ", change from " + old_freq + " to " + freq);}
    }catch(Exception e){   
        Log.e(TAG, e.toString());
        Log.e(TAG, "Can't change the cpu freq: " + 
              freqFileName +
              ", ignore it.");
    }finally{
        if (fin != null) {
            try {
                fin.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } 
    return return_value;
}

8.常用的正則表達式:如
public static boolean isNumeric(String str){ //是數(shù)字返回true
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}

private boolean ifLegal(String motorID){
    char c = motorID.charAt(0);
    String sub= motorID.substring(1);
    if (isNumeric(sub) && !Character.isLowerCase(c)){   //判斷大寫字母
        return true;
    }
    return false;
}

9.創(chuàng)建自己需要的簡單的類:
如:
public class Point{
private int pointX,pointY;

    public Point(int x,int y){
        pointX=x;
        pointY=y;
    }
    
    public void putPointX(int point){
        pointX = point;
    }
    public int getPointX(){
        return pointX;
    }
    
    public void putPointY(int point){
        pointY = point;
    }
    public int getPointY(){
        return pointY;
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容