fileoutputstream

Why does saving a bitmap take so long?

和自甴很熟 提交于 2019-11-29 07:34:42
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(), myBitmapPic.getHeight(), CvType.CV_8UC1); Utils.bitmapToMat(myBitmapPic, image); Imgproc.cvtColor(image,

con.txt and C++

寵の児 提交于 2019-11-29 04:12:18
#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? CON is a reserved device name on Windows platforms. It shouldn't be used as a file name, even with an extension. From the documentation : Do not use the following reserved device names for the

How do you play Android InputStream on MediaPlayer?

自闭症网瘾萝莉.ら 提交于 2019-11-28 23:25:16
So I have a small audio file in my assets folder and I wanted to open a InputStream to write to a buffer, then write to a temporary File, then I open up the MediaPlayer to play that temporary File. Problem is, when the media player hits mp.Prepare(), it doesn't play and never reaches the toast. Has anyone ever done this before? public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); InputStream str; try { str = this.getAssets().open("onestop.mid"); Toast.makeText(this, "Successful Input Stream Opened.", Toast.LENGTH_SHORT).show();

Read/write file to internal private storage

◇◆丶佛笑我妖孽 提交于 2019-11-28 20:51:18
I'm porting the application from Symbian/iPhone to Android, part of which is saving some data into file. I used the FileOutputStream to save the file into private folder /data/data/package_name/files : FileOutputStream fos = iContext.openFileOutput( IDS_LIST_FILE_NAME, Context.MODE_PRIVATE ); fos.write( data.getBytes() ); fos.close(); Now I am looking for a way how to load them. I am using the FileInputStream , but it allows me to read the file byte by byte, which is pretty inefficient: int ch; StringBuffer fileContent = new StringBuffer(""); FileInputStream fis = iContext.openFileInput( IDS

FileOutputStream: Does the “close” method calls also “flush”?

喜欢而已 提交于 2019-11-28 06:54:21
I'm really confused about flush and close method.In my code I always close my FileOutputStream object. But I want to know that if I have to use flush method here, and where can I use it? I will write a project that download 4 or 5 files repeatedly. I will write a method(for download files) and my method will be in a loop and download files repeatedly.My method will have a code like this. Does the close method calls flush , or do I have to use flush before closing? try { InputStream inputStream = con.getInputStream(); FileOutputStream outputStream = new FileOutputStream("C:\\programs\\TRYFILE

FileOutputStream crashes with “open failed: EISDIR (Is a directory)” error when downloading image

Deadly 提交于 2019-11-28 06:49:16
I'm trying to download an iamge from the internet, Here is the code: try { String imgURL = c.imgURL; String imgPATH = c.imgPATH; URL url = new URL(imgURL); URLConnection conexion = url.openConnection(); conexion.connect(); int lenghtOfFile = conexion.getContentLength(); try { File f = new File(imgPATH); f.mkdirs(); BufferedInputStream input = new BufferedInputStream(url.openStream()); BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(imgPATH), 8192); // CRASH HERE byte data[] = new byte[8192]; long total = 0; int count = 0; int updateUILimiter = 0; while ((count =

PrintWriter to append data if file exist

大兔子大兔子 提交于 2019-11-28 05:47:09
问题 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

How to write new line in Java FileOutputStream

邮差的信 提交于 2019-11-28 01:49:09
I want to write a new line using a FileOutputStream ; I have tried the following approaches, but none of them are working: encfileout.write('\n'); encfileout.write("\n".getbytes()); encfileout.write(System.getProperty("line.separator").getBytes()); It could be a viewer problem... Try opening the file in EditPlus or Notepad++. Windows Notepad may not recognise line feed of another operating system. In which program are you viewing the file now? AlexR This should work. Probably you forgot to call encfileout.flush() . However this is not the preferred way to write texts. You should wrap your

How do you play Android InputStream on MediaPlayer?

允我心安 提交于 2019-11-27 14:43:46
问题 So I have a small audio file in my assets folder and I wanted to open a InputStream to write to a buffer, then write to a temporary File, then I open up the MediaPlayer to play that temporary File. Problem is, when the media player hits mp.Prepare(), it doesn't play and never reaches the toast. Has anyone ever done this before? public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); InputStream str; try { str = this.getAssets().open

How can I let users access the internal storage directory of my app?

五迷三道 提交于 2019-11-27 14:05:23
My app stores files in its internal storage directory (/Android/data/com.mycompany.myapp/files, as returned by getFilesDir()), and I would like to allow users to access those files directly from a file management app on their mobile device or the Android File Transfer desktop appplication. The Storage Options developer guide says: By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). "By default" implies that I can change the default permissions to allow users to access these files, but I can't find any