fileoutputstream

OutputStreamWriter does not append

自作多情 提交于 2019-12-01 00:45:37
问题 Original code and its working saving the data to the SD Card // Writing data to internal storage btnSaveData.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isSDCardWritable()) { String dataToSave = etData.getText().toString(); try { // SD Card Storage File sdCard = Environment.getExternalStorageDirectory(); File directory = new File(sdCard.getAbsolutePath()+"/MyFiles"); directory.mkdirs(); File file = new File(directory, "text.txt");

Storing key using KeyStore in Android

人盡茶涼 提交于 2019-11-30 21:04:31
I am using KeyStore to protect my private key but when the line: FileOutputStream fos = ctx.openFileOutput("bs.keystore", Context.MODE_PRIVATE); is executed I have this exception: 'java.lang.NullPointerException'. I don't understand where is the problem. Code: private Context ctx; public DataSec(Context ctx) { ctx = this.ctx; } public void genKey() throws Exception { SecretKey key = KeyGenerator.getInstance("AES").generateKey(); KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(null, "clavedekey".toCharArray()); PasswordProtection pass = new PasswordProtection("fedsgjk"

Storing key using KeyStore in Android

被刻印的时光 ゝ 提交于 2019-11-30 17:03:12
问题 I am using KeyStore to protect my private key but when the line: FileOutputStream fos = ctx.openFileOutput("bs.keystore", Context.MODE_PRIVATE); is executed I have this exception: 'java.lang.NullPointerException'. I don't understand where is the problem. Code: private Context ctx; public DataSec(Context ctx) { ctx = this.ctx; } public void genKey() throws Exception { SecretKey key = KeyGenerator.getInstance("AES").generateKey(); KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

Volley - download directly to file (no in memory byte array)

折月煮酒 提交于 2019-11-30 14:04:57
问题 I'm using Volley as my network stack in a project I'm working on in Android. Part of my requirements is to download potentially very large files and save them on the file system. Ive been looking at the implementation of volley, and it seems that the only way volley works is it downloads an entire file into a potentially massive byte array and then defers handling of this byte array to some callback handler. Since these files can be very large, I'm worried about an out of memory error during

Volley - download directly to file (no in memory byte array)

梦想与她 提交于 2019-11-30 09:15:50
I'm using Volley as my network stack in a project I'm working on in Android. Part of my requirements is to download potentially very large files and save them on the file system. Ive been looking at the implementation of volley, and it seems that the only way volley works is it downloads an entire file into a potentially massive byte array and then defers handling of this byte array to some callback handler. Since these files can be very large, I'm worried about an out of memory error during the download process. Is there a way to tell volley to process all bytes from an http input stream

BitmapFactory.decodeFile returns null even image exists

 ̄綄美尐妖づ 提交于 2019-11-30 08:58:09
问题 Saving the file: FileOutputStream fo = null; try { fo = this.openFileOutput("test.png", Context.MODE_WORLD_READABLE); } catch (FileNotFoundException e) { e.printStackTrace(); } bitmap.compress(CompressFormat.PNG, 100, fo) Loading the file: String fname = this.getFilesDir().getAbsolutePath()+"/test.png"; Bitmap bMap = BitmapFactory.decodeFile(fname); i.setImageBitmap(bMap); The last line gives a null pointer exception, why is BitmapFactory.decodeFile returning null? I can verify that the file

con.txt and C++

不问归期 提交于 2019-11-30 07:35:27
问题 #include <fstream> int _tmain(int argc, _TCHAR* argv[]) { std::ofstream F("con.txt", std::ios::out); F << "some text in con.txt"; F.close(); return 0; } output: some text in con.txt If i replace " con.txt " with " something.txt " then something.txt will contains the string " some text in something.txt ." I think that the file con.txt bind with a console file... What is real happened in the first case? 回答1: CON is a reserved device name on Windows platforms. It shouldn't be used as a file name

Java FileOutputStream: path relative to program folder?

邮差的信 提交于 2019-11-29 14:49:57
What is the best way to find a path relative to the folder where a java application is "installed"? I have a class with a static method: public static void saveToFile(String fileName) When I call it with an absolute path, it works, but what I really want is the relative path to where the application is run from, and a folder. I have not deployed my application, but right now I want to find a path relative to the (Netbeans) project root, and a folder within called data: ProjectName\data\file.dat . Should I use the File class or make it into a URI or something? Note that I prefer it to be system

PrintWriter to append data if file exist

好久不见. 提交于 2019-11-29 12:03:33
I have a savegame file called mysave.sav and I want to add data to this file if the file already exists. If the file doesn't exists, I want to create the file and then add the data. Adding data works fine. But appending data overwrites existing data. I followed the instructions of axtavt here ( PrintWriter append method not appending ). String savestr = "mysave.sav"; File f = new File(savestr); PrintWriter out = new PrintWriter(savestr); if ( f.exists() && !f.isDirectory() ) { out = new PrintWriter(new FileOutputStream(new File(savestr), true)); out.append(mapstring); out.close(); } else { out

BitmapFactory.decodeFile returns null even image exists

☆樱花仙子☆ 提交于 2019-11-29 09:35:08
Saving the file: FileOutputStream fo = null; try { fo = this.openFileOutput("test.png", Context.MODE_WORLD_READABLE); } catch (FileNotFoundException e) { e.printStackTrace(); } bitmap.compress(CompressFormat.PNG, 100, fo) Loading the file: String fname = this.getFilesDir().getAbsolutePath()+"/test.png"; Bitmap bMap = BitmapFactory.decodeFile(fname); i.setImageBitmap(bMap); The last line gives a null pointer exception, why is BitmapFactory.decodeFile returning null? I can verify that the file is getting saved correctly as I can pull it using adb and see the png displaying properly. If the