fileinputstream

Getting the file used by a FileInputStream [duplicate]

半城伤御伤魂 提交于 2020-04-16 02:06:09
问题 This question already has answers here : Get file name from FileOutputStream (5 answers) Closed 3 years ago . Is it possible to obtain the File being used by a FileInputStream ? FileInputStream does not appear to have any methods for retrieving it. 回答1: There are no direct methods in FileInputStream API, but if you really wanted, you can use java reflection API to get the path (actual file name with full path) as shown below: FileInputStream fis = new FileInputStream(inputFile); Field field =

Image uploaded from the android app space seems corrupted

自作多情 提交于 2020-02-06 02:48:34
问题 In my android application, I need to upload a image in my Assets/Drawable/raw folder to the server. I tried the following: InputStream fileInputStream; if(imageChanged) { File file = New File("filename"); fileInputStream = new FileInputStream(file); }else { fileInputStream = ctx.getAssets().open("default.png"); } int bytesAvailable; byte[] buffer = new byte[102400]; while((bytesAvailable = fileInputStream.available()) > 0) { int bufferSize = Math.min(bytesAvailable, 102400); if(bufferSize

strip data from text file using regex

 ̄綄美尐妖づ 提交于 2020-01-24 20:56:25
问题 Im going to start by posting what the data from the text file looks like, this is just 4 lines of it, the actually file is a couple hundred lines long. Friday, September 9 2011 5:00AM - 11:59PM STH 1102 HOLD DO NOT BOOK Report Printed on 9/08/2011 at 2:37 PM Page 1 of 1 Friday, September 9 2011 5:00AM - 11:00PM STH 4155 (BOARDROOM) HOLD - DO NOT BOOK Hold - Do Not Book Report Printed on 9/08/2011 at 2:37 PM Page 1 of 1 Friday, September 9 2011 5:00AM - 11:59PM UC 2 (COMPUTER LAB) HOLD DO NOT

How to write a method header that throws exception

依然范特西╮ 提交于 2020-01-24 15:28:36
问题 "Given that FileInputStream’s constructor throws FileNotFoundException, which is a subclass of Exception, write the header for a public method named process that takes a String parameter and returns nothing, and whose body instantiates a FileInputStream object and does not contain a try-catch statement." I know it's a too-simple question but I want to make sure I'm not messing up in a dumb way. Also, not sure whether to use FileNotFoundException or just Exception or IO, etc. public process

Write and read binary files in Android

北慕城南 提交于 2020-01-23 08:12:27
问题 I created a custom object of type Task and I want to save it in a binary file in internal storage. Here is the class I created: public class Task { private String title; private int year; private int month; private int day; private int hour; private int minute; public Task(String inputTitle, int inputYear, int inputMonth, int inputDay, int inputHour, int inputMinute) { this.title = inputTitle; this.year = inputYear; this.month = inputMonth; this.day = inputDay; this.hour = inputHour; this

Resolving java.lang.outofmemory error causing half of the file to be uploaded to server

佐手、 提交于 2020-01-17 00:40:50
问题 I am trying to upload large video files to the server. I wrote a piece of code which works well for the image so I thought I should work it for the video too. I wrote the below code. public int uploadFile(String sourceFileUri) { String fileName = sourceFileUri; //Log.v("ONMESSAGE", "File type is " + filetype + "File name is " + fileName); HttpURLConnection conn = null; DataOutputStream dos = null; String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "*****"; int bytesRead,

Java read in single file and write out multiple files

寵の児 提交于 2020-01-15 12:44:27
问题 I want to write a simple java program to read in a text file and then write out a new file whenever a blank line is detected. I have seen examples for reading in files but I don't know how to detect the blank line and output multiple text files. fileIn.txt: line1 line2 line3 fileOut1.txt: line1 line2 fileOut2.txt: line3 回答1: Just in case your file has special characters , maybe you should specify the encoding . FileInputStream inputStream = new FileInputStream(new File("fileIn.txt"));

Unable to merge two mp3 files

可紊 提交于 2020-01-15 08:18:08
问题 public class MainActivity extends Activity { FileInputStream fistream2,fistream1; File newFile=new File(Environment.getExternalStorageDirectory() +File.separator +"newfolder" //folder name +File.separator +"media" +File.separator +"player"+File.separator+"theonkar10.mp3"); File newFile1=new File(Environment.getExternalStorageDirectory() +File.separator +"newfolder" //folder name +File.separator +"media" +File.separator +"player"+File.separator+"1.mp3"); File newFile2=new File(Environment

How to convert FileInputStream to InputStream? [closed]

本小妞迷上赌 提交于 2020-01-11 15:05:22
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I just want to convert a FileInputStream to an InputStream , how can I do that? e.g FileInputStream fis = new FileInputStream("c://filename"); InputStream is = ?; fis.close(); 回答1: You would typically first read

Grails : Edit (form: multipart) file (from client) and send it back to the client

强颜欢笑 提交于 2020-01-07 03:08:07
问题 This is what I need to do. 1) Accept an xlsx/xls file from client. 2) Backend will receive it in the form of multipart file 3) The file will be processed and if the format of the data is invalid, that same file will be updated and the error message will be written in the side of the input of the client. 4) this modified file will be sent back to the user. So far this is what i've done. def generateErrorReport(ServletResponse response, Map messageCollections, MultipartFile file, String ext){