Code example for DataOutputStream

Methods: close, flush, writeBytes

0
SampleNum = SampleNum + 1;
 
			 
	        try {           
	            out.writeBytes(S_x);
	            out.writeBytes(",");
	             
	            out.writeBytes(S_y);
	            out.writeBytes(",");
	             
	            out.writeBytes(S_z);
	            out.writeBytes(",");
	             
	            out.writeBytes(S_x_Raw);
	            out.writeBytes(",");
	             
	            out.writeBytes(S_y_Raw);
	            out.writeBytes(",");
	             
	            out.writeBytes(S_z_Raw);
	            out.writeBytes(",");
	             
	            out.writeBytes(S_s);
	            out.writeBytes(";");
	             
	        } catch (IOException e) {
	            // TODO Auto-generated catch block 
	            e.printStackTrace();
	        } 
			 
			 
		} 
	} 
	 
	private void createAndRecordFile(){ 
		 
		 
        String filepath = Environment.getExternalStorageDirectory().getPath();
        File file = new File(filepath,VIBE_RECORDER_FOLDER);
         
        if(!file.exists()){
                file.mkdirs();
        } 
         
       // return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".dat"); 
       // filename = (System.currentTimeMillis() + ".dat");         
        filename = (VIBE_RECORDER_WORK_FILE + ".dat");
        outputFile = new  File(file.getAbsolutePath() + "/" + filename);
         
        boolean deleted = outputFile.delete(); //Delete file
         
       // FileOutputStream osr = null; 
       // DataOutputStream out = null; 
         
        if(osr==null){
            try { 
            	osr = new FileOutputStream(outputFile);
            	out = new DataOutputStream(osr);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block 
                e.printStackTrace();
            } 
        } 
 
        try { 
            out.writeBytes("999,999,999,999,999,999,999;");
        } catch (IOException e) {
            // TODO Auto-generated catch block 
            e.printStackTrace();
        } 
 
         
} 
 
	private void StopAndCloseFile(){ 
        try { 
        	out.writeBytes("111,111,111,111,111,111,111;");
            out.flush();
            out.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block 
            e.printStackTrace();
        }