inputstream

how to set read only access for file using java

有些话、适合烂在心里 提交于 2020-01-06 02:19:08
问题 How to set read-only access for a file that's been created and written using java InputStream API. 回答1: In my opinion, it's good to check whether the file has been created or exists first and then set the read only flag. File file = new File("C:/path/file.txt"); if (file.exists()) { file.setReadOnly(); } else { System.out.println("File does not exists."); } 回答2: Well their are two ways to do it. The first would be: myFile.setReadable(false); . This make the file unreadable by all applications

Java process inputstream in thread

喜欢而已 提交于 2020-01-06 01:46:19
问题 I develop an Eclipse plugin and I have a problem My code is the following one: String run_pelda = "cmd.exe /C pelda.exe"; Runtime pelda_rt = Runtime.getRuntime(); Process pelda_proc = javacheckgen_rt.exec(run_pelda); And after I would like to read the inputstream: InputStream toolstr = tool_proc.getInputStream(); InputStreamReader r = new InputStreamReader(toolstr); BufferedReader in = new BufferedReader(r); But my new Eclipse instsnce freezes. I think I should do it in java threads, but

Using inputStream and OutputStream to read and write data to a process

泄露秘密 提交于 2020-01-05 23:45:08
问题 I am currently running a .class file as a process. The .class file is a simple program that asks the user to input a number, takes the input and prints the user's input back to the screen. Up to now, i have managed to print the "Enter a number: " statement from the process on the console through InputStream and write the input entered by the user through OutputStream . I am unable to print the last statements on the screen, which should be "You entered : " + userinput My code is: String

Saving Image Retrieved from InputStream locally

与世无争的帅哥 提交于 2020-01-05 12:32:34
问题 I used the following code to retrieve an image from a url and display it within an activity. InputStream is = (InputStream) new URL(url[0]).getContent(); Drawable d = Drawable.createFromStream(is, "imagename"); ImageView... Now I want to save this image (Drawable d) locally when a user clicks a button so I can display it again in another activity (along with a few other tasks). I'd like to store it within the app folder itself rather than on the SD card. How would I do this? Thanks! Shannon

Saving Image Retrieved from InputStream locally

雨燕双飞 提交于 2020-01-05 12:31:10
问题 I used the following code to retrieve an image from a url and display it within an activity. InputStream is = (InputStream) new URL(url[0]).getContent(); Drawable d = Drawable.createFromStream(is, "imagename"); ImageView... Now I want to save this image (Drawable d) locally when a user clicks a button so I can display it again in another activity (along with a few other tasks). I'd like to store it within the app folder itself rather than on the SD card. How would I do this? Thanks! Shannon

Send data from InputStream over Akka/Spring stream

China☆狼群 提交于 2020-01-05 09:21:32
问题 Here is my previous question: Send big file over reactive stream I have managed to send file over Akka stream using FileIO.fromPath(Paths.get(file.toURI())) and it works fine. However, I would like to compress and encrypt file before sending it. I have created method, that opens FileInputStream, routes it through compression stream and then through encryption stream and now I would like to direct it into socket using Akka stream. File -> FileInputStream -> CompressedInputStream ->

Java InputStream read buffer

独自空忆成欢 提交于 2020-01-05 04:20:30
问题 Say I'm trying to read from a Java InputStream like this: ZipInputStream zis = new ZipInputStream(new FileInputStream("C:\\temp\\sample3.zip")); zis.getNextEntry(); byte[] buffer2 = new byte[2]; int count = zis.read(buffer2)); if(count != -1) //process... else...//something wrong, abort I'm parsing a binary file and I set my buffer to 2 in this case because I want to read the next short. I would set my buffer to size 4 if I want to read the next int and so on for other types. The problem is

How to interrupt reading on System.in?

谁都会走 提交于 2020-01-05 04:08:05
问题 If I start reading from System.in , it will block the thread until it gets data. There is no way to stop it. Here are all the ways that I've tried: Interrupting the thread Stopping the thread Closing System.in Calling System.exit(0) does indeed stop the thread, but it also kills my application so not ideal. Entering a char into the console makes the method return, but I can't rely on user input. Sample code that does not work: public static void main(String[] args) throws InterruptedException

AudioTrack in MODE_STREAM has no sound

百般思念 提交于 2020-01-04 15:50:41
问题 I've been stuck on this problem for days. I'm at the stage now where I'm just trying to get a working example to build from, but I can't even reach that point. My question is based on this example. I've included the source (and solution) into my own code, and can see the buffer is being written to, but no sound comes from the device. I'm struggling to identify how to debug this further. package com.example.audio; import com.example.R; import java.io.IOException; import java.io.InputStream;

Sending data by FTP

為{幸葍}努か 提交于 2020-01-04 02:54:19
问题 Im trying to upload a file and im having a few problems. I have an input stream from a local path: self.stmIn = [NSInputStream inputStreamWithFileAtPath:localPath]; The variable localPath has this URL: /Users/JBG/Library/Application Support/iPhone Simulator/6.0/Applications/734F4DC6-8683-42BB-AB0D-A5553BC22C55/Documents/100046-003.jpg I can open the stream without any problem. The problem comes when i try to read it: bytesRead = [self.stmIn read:self.buffer maxLength:kSendBufferSize]; The