文件存储

来源:互联网 发布:恢复数据多少钱 编辑:程序博客网 时间:2024/04/27 13:03

Android 文件保存;

public String mSdcardDir = null;
 public String mWorkDir = "/test";

public String myDateName;

mSdcardDir = Environment.getExternalStorageDirectory().toString();
 mWorkDir = String.format("%s%s", mSdcardDir, mWorkDir);

if( createWorkDir mWorkDir)

{

Log.e(TAG,"can't create file ");

}

int previewNum=0;

myDateName= String.format("%s/%d_.yuv",mWorkDir,previewNum);

saveImage(myDateName,data);

public boolean createWorkDir(String dirName)
 {
 if (dirName == null || dirName.toLowerCase().compareTo("null") == 0)
 return false;
 File pFile = new File(dirName);
 if (!pFile.exists())
 {
 try
 {
 boolean rev = pFile.mkdirs();
 if (rev)
 return true;
 else
 return false;
 } catch (Exception e)
 {
 e.printStackTrace();
 return false;
 }
 }
 return true;
 }

public static boolean saveImage(String fullpath, byte[] jpegData)
 {
 boolean success = false;
 if (null != fullpath)
 {
 try
 {
 File file = new File(fullpath);
 FileOutputStream fs = new FileOutputStream(fullpath);
 fs.write(jpegData);
 fs.close();
 success = true;
 } catch (FileNotFoundException e)
 {

} catch (IOException e)
 {

} finally
 {

}
 return success;
 } else
 return success;
 }
                                  

Java 文件保存

try

{

FileOutputStream fout=new FileOutputStream("D:\\eer.txt");

try

{

byte []ds={'1','2','3'};

fout.write(ds, 0, 3);

fout.flush();

fout.close();

catch (IOException e)

{

// TODO Auto-generated catch block

e.printStackTrace();

}

catch (FileNotFoundException e)

{

// TODO Auto-generated catch block

e.printStackTrace();

}

                                                                         

                                     

C文件的读写

File *pFile;

??????????

pFile=fopen("/mnt/sdcard/" ,"rb");

fwrite( dataBuffer , size,num, pfile );

Fclose(pFile);

Android 文件保存;

public String mSdcardDir = null;
 public String mWorkDir = "/test";

public String myDateName;

mSdcardDir = Environment.getExternalStorageDirectory().toString();
 mWorkDir = String.format("%s%s", mSdcardDir, mWorkDir);

if( createWorkDir mWorkDir)

{

Log.e(TAG,"can't create file ");

}

int previewNum=0;

myDateName= String.format("%s/%d_.yuv",mWorkDir,previewNum);

saveImage(myDateName,data);

public boolean createWorkDir(String dirName)
 {
 if (dirName == null || dirName.toLowerCase().compareTo("null") == 0)
 return false;
 File pFile = new File(dirName);
 if (!pFile.exists())
 {
 try
 {
 boolean rev = pFile.mkdirs();
 if (rev)
 return true;
 else
 return false;
 } catch (Exception e)
 {
 e.printStackTrace();
 return false;
 }
 }
 return true;
 }

public static boolean saveImage(String fullpath, byte[] jpegData)
 {
 boolean success = false;
 if (null != fullpath)
 {
 try
 {
 File file = new File(fullpath);
 FileOutputStream fs = new FileOutputStream(fullpath);
 fs.write(jpegData);
 fs.close();
 success = true;
 } catch (FileNotFoundException e)
 {

} catch (IOException e)
 {

} finally
 {

}
 return success;
 } else
 return success;
 }
                                  

Java 文件保存

try

{

FileOutputStream fout=new FileOutputStream("D:\\eer.txt");

try

{

byte []ds={'1','2','3'};

fout.write(ds, 0, 3);

fout.flush();

fout.close();

catch (IOException e)

{

// TODO Auto-generated catch block

e.printStackTrace();

}

catch (FileNotFoundException e)

{

// TODO Auto-generated catch block

e.printStackTrace();

}

                                                                         

                                     

C文件的读写

File *pFile;

??????????

if( pFile= fopen("/mnt/sdcard/" ,"rb") )

{

fwrite( dataBuffer , size,num, pfile );

Fclose(pFile);

}

 

原创粉丝点击