fileoutputstream

How to create a directory, and save a picture to it in Android

无人久伴 提交于 2019-12-24 13:47:43
问题 This is a function I have written that tries to: Create a folder with the users name Save a .jpg inside of that folder The folder creation works fine, however when I try to save the pictures, they all save with the correct name, however they do not save in their intended folders. In other words, instead of having a folder containing a bunch of folders each containing one picture, I have one folder containing a bunch of empty folders, and a bunch of pictures all outside their folders (I can

Writing to external storage filenotfoundexception

廉价感情. 提交于 2019-12-24 08:19:24
问题 I am attempting to write a file to external storage in android. I keep getting the error, "java.io.FileNotFoundException: /mnt/sdcard/Survey.txt (Is a directory)." The method that contains the code for this is as follows: public String sendFile(System system) throws FileNotFoundException { File writeable = new File(Environment.getExternalStorageDirectory() .getAbsolutePath() + "/Survey.txt"); try { writeable.createNewFile(); } catch (IOException e1) { // TODO Auto-generated catch block e1

Return as ByteArrayOutputStream instead of FileOutputStream

◇◆丶佛笑我妖孽 提交于 2019-12-23 06:37:26
问题 I have a requirement to generate PDF file from JSON Objects and am able to produce PDF document using Apache FOP and Java. But i want to return the PDF file as ByteArrayOutputStream and then i have to encode like this Base64.getEncoder().encodeToString(baos.toByteArray()) . Please find the below code where am able to generate PDF file, instead of FileOutputStream i want to return as ByteArrayOutputStream . ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Transformer

Android save photo on disk in private mode

心已入冬 提交于 2019-12-23 05:06:42
问题 I'm able to save a Image in disk using : String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath(); String fileName = imageId + ".png"; String filePath = baseDir + File.separator + fileName; File file = new File(filePath); if(!file.exists()) { out = new FileOutputStream(baseDir + File.separator + fileName); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); } But all the images saved are visible in the gallery of the phone .. How can I hide them to the user ? Is there a

Close a file created with FileOutputStream, for a next delete

拥有回忆 提交于 2019-12-19 18:28:23
问题 I am currently facing some problem with a FileOutputStream in my Java code. Actually I am using a FileOutputStream for creating a file, but then once the file is created there is no way for deleting it. As far as I could understand, this may come from the fact that the FileOutputstream is not closed. On below my summarized code : outFile = new FileOutputStream(dir+"\\"+fileName); outFile.write("Test"); outFile.flush(); outFile.close(); outFile = null; System.gc(); Then there is no way to

Close a file created with FileOutputStream, for a next delete

社会主义新天地 提交于 2019-12-19 18:27:31
问题 I am currently facing some problem with a FileOutputStream in my Java code. Actually I am using a FileOutputStream for creating a file, but then once the file is created there is no way for deleting it. As far as I could understand, this may come from the fact that the FileOutputstream is not closed. On below my summarized code : outFile = new FileOutputStream(dir+"\\"+fileName); outFile.write("Test"); outFile.flush(); outFile.close(); outFile = null; System.gc(); Then there is no way to

Close a file created with FileOutputStream, for a next delete

…衆ロ難τιáo~ 提交于 2019-12-19 18:27:06
问题 I am currently facing some problem with a FileOutputStream in my Java code. Actually I am using a FileOutputStream for creating a file, but then once the file is created there is no way for deleting it. As far as I could understand, this may come from the fact that the FileOutputstream is not closed. On below my summarized code : outFile = new FileOutputStream(dir+"\\"+fileName); outFile.write("Test"); outFile.flush(); outFile.close(); outFile = null; System.gc(); Then there is no way to

Android: Write text to txt

早过忘川 提交于 2019-12-19 09:14:24
问题 With the following code, I try to write to my sdcard: public void writedata(String data) { //BufferedWriter out = null; System.out.println(data); try{ FileOutputStream out = new FileOutputStream(new File("/sdcard/tsxt.txt")); out.write(data.getBytes()); out.close(); } catch (Exception e) { //fehlende Permission oder sd an pc gemountet} System.out.println("CCCCCCCCCCCCCCCCCCCCCCCALSKDJLAK"); } } The permission in the Manifest: <uses-permission android:name="android.permission.WRITE_EXTERNAL

Java FileOutputStream: path relative to program folder?

a 夏天 提交于 2019-12-18 08:49:20
问题 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

Why does saving a bitmap take so long?

一笑奈何 提交于 2019-12-18 04:17:21
问题 So I have an app on Google Glass that takes a picture, then converts it to grayscale and overwrites the original image in memory: private void rGBProcessing (final String picturePath, Mat image) { //BitmapFactory Creates Bitmap objects from various sources, //including files, streams, and byte-arrays Bitmap myBitmapPic = BitmapFactory.decodeFile(picturePath); image = new Mat(myBitmapPic.getWidth(), myBitmapPic.getHeight(), CvType.CV_8UC4); Mat imageTwo = new Mat(myBitmapPic.getWidth(),