Code example for BufferedWriter

Methods: newLineappend

0
        if (logFile.exists()) {
            logFile.delete();
        } 
        try {  
            logFile.createNewFile();
            buf = new BufferedWriter(new FileWriter(logFile, true));
            isEnabled = true;
            appendPhoneInfo(); 
        }catch (IOException e){ 
            e.printStackTrace(); 
        }  
    } 
     
    public static void stopLogging() { 
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss",Locale.getDefault());
        String currentDateandTime = sdf.format(new Date());
        if (logFile != null) {
            logFile.renameTo(new File(folder+File.separator+"Owncloud_"+currentDateandTime+".log"));
           
            isEnabled = false;
            try { 
                buf.close();
            } catch (IOException e) {
                e.printStackTrace();
            }  
         
        } 
         
    } 
     
    private static void appendPhoneInfo() { 
        appendLog("Model : " + android.os.Build.MODEL);
        appendLog("Brand : " + android.os.Build.BRAND);
        appendLog("Product : " + android.os.Build.PRODUCT);
        appendLog("Device : " + android.os.Build.DEVICE);
        appendLog("Version-Codename : " + android.os.Build.VERSION.CODENAME);
        appendLog("Version-Release : " + android.os.Build.VERSION.RELEASE);
    } 
     
    private static void appendLog(String text) { 
        if (isEnabled) {
           try {  
               buf.append(text); 
               buf.newLine(); 
           } catch (IOException e) { 
               e.printStackTrace(); 
        }  
    } 
} 
Experience pair programming with AI  Get Codota for Java