Register to be default app for custom file type

You can add the following to the AndroidManifest.xml file inside the activity that has to open the file (pdf in our case) <intent-filter > <action android:name=”android.intent.action.VIEW” /> <category android:name=”android.intent.category.DEFAULT” /> <data android:mimeType=”application/pdf” /> </intent-filter> Make sure you specify the proper mime format. The user will be prompted to choose your app if she wants to … Read more

Detect if PDF file is correct (header PDF) [closed]

I check Header PDF like this: public bool IsPDFHeader(string fileName) { byte[] buffer = null; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); long numBytes = new FileInfo(fileName).Length; //buffer = br.ReadBytes((int)numBytes); buffer = br.ReadBytes(5); var enc = new ASCIIEncoding(); var header = enc.GetString(buffer); //%PDF−1.0 // If you are loading it into … Read more

How can I style a file input field in Firefox?

Many of the answers above are quite old. In 2013 a much simpler solution exists: nearly all current browsers… Chrome IE Safari Firefox with a few-line fix pass through click events from labels. Try it here: Style the <label> however you you would like your file upload to be. Set for=”someid” attribute on the … Read more

How to create a dynamic file + link for download in Javascript? [duplicate]

Here’s a solution I’ve created, that allows you to create and download a file in a single click: <html> <body> <button onclick=’download_file(“my_file.txt”, dynamic_text())’>Download</button> <script> function dynamic_text() { return “create your dynamic text here”; } function download_file(name, contents, mime_type) { mime_type = mime_type || “text/plain”; var blob = new Blob([contents], {type: mime_type}); var dlink = document.createElement(‘a’); … Read more

Read from file or stdin

You’re thinking it wrong. What you are trying to do: If stdin exists use it, else check whether the user supplied a filename. What you should be doing instead: If the user supplies a filename, then use the filename. Else use stdin. You cannot know the total length of an incoming stream unless you read … Read more

Using BufferedReader to read Text File

This is the problem: while (br.readLine() != null) { System.out.println(br.readLine()); } You’ve got two calls to readLine – the first only checks that there’s a line (but reads it and throws it away) and the second reads the next line. You want: String line; while ((line = br.readLine()) != null) { System.out.println(line); } Now we’re … Read more