Read file with nio and flush with servlet
Can I read file, by using java.nio (for example by FileInputStream.getChannel()) and then flush the file content thru the servlet?
I kwow about reading without java.nio, get a byte array and then flush it by httpservletresponse writer or outputstream, but I wish to know if it is possibile with java.nio reading.
thanks
I'm doing it only for file reading..
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
FileInputStream fis = null;
try
String path = "/var/hello.txt";
fis = new FileInputStream(path);
FileChannel channel = fis.getChannel();
ByteBuffer bb = ByteBuffer.allocate((int) channel.size());
channel.read(bb);
byte[] data2 = bb.array();
channel.close();
out.write(new String(data2));
} catch (FileNotFoundException ex)
ex.printStackTrace();
} finally
try
fis.close();
} catch (IOException ex)
ex.printStackTrace();
out.close();
}
Similar Messages
-
Adobe error 1305 error reading file...and you have acces to it?
adobe error 1305 error reading file...and you have acces to it? Can somebody help me with this? I'm trying to install Acrobat Pro XI
See if any of the instructions provided at the following link help resolve the problem:
http://helpx.adobe.com/creative-suite/kb/error-1305-try-install-product.html -
I have an airport express and want to know how to set up two different wireless networks. One with 5GHZ and one with 2.4GHZ so different devices can connect to either. I have an iphone 4 that will not connect to 5ghz.
thank you!Your AirPort Express is already providing two separate 2.4 GHz and 5 GHz bands, but each band is using the same wireless network name.
This is the default setup for the AirPort Express, which is recommended for most users. The theory here is that devices will automatically connect to the best quality signal based on their capabilities and distance in relation to the AirPort Express.
It is possible to assign a different name to the 5 GHz band, and then "point" devices at that network to connect. Some users swear by this option.....(I am not one of them).... but you might want to give it a try to see how it works for you.
Open Macintosh HD > Applications > Utilities > AirPort Utility
Click on the AirPort Express
Click Edit in the smaller window that appears
Click the Wireless tab at the top of the next window
Click Wireless Options near the bottom of the next window
Enter a check mark next to 5 GHz Name.....which will automatically add "5 GHz" to the network name....so you can identify it
Click Save, then click Update and wait a full minute for the Express to restart
Now you will need to "point" your 5 GHz capable devices at the 5 GHz network name. 2.4 GHz devices will connect to your "other" network name. -
Why is my airportxpr only working with Itunes and not with another music program
why is my airportxpr only working with Itunes and not with another music program??
I can not select/see other outputs in my sound selector.You have not indicated which OS or which music program you have so I have listed a program called Airfoil to try for both Windows and Mac - it may work for you
for Windows - http://rogueamoeba.com/airfoil/windows/
for Mac - http://rogueamoeba.com/airfoil/mac/ -
Does Apple make/sell the new "Apple In-Ear Headphones with Remote and Mic" with a one sided configuration? So that a person that is deaf in one can hear both sides of a stereo recording? Also, since the "other" bud is not necessary/useful...it's removed.
As far as I know, Apple sells no such configuration. However, under Settings > General > Accessability, there is an option to play back audio in monoural mode, which would then play both halves of a stereo mix in each earbud.
Hope that helps. -
How do I delete sites created with iWeb and posted with .mac after a format
I am confused about how to delete a couple of sites that I created with iWeb and posted with my .mac after I did a format reload?
I have tried everything. The original files are not on my MacBook Pro because of the format.
I also see them in my idisc, but I is my understanding that on my MacBook Pro that I can delete the files, but they are hosted online. On the online idisk I cannot delete them because there is no option. Please help!!!Using the file menu in Finder:
Go/iDisk/My iDisk/Web/Sites/iWeb/YourSitesAreHere
Highlight selected files and Command/Delete. You will receive a drop down asking you if you are sure; click OK and the files/sites will be deleted immediately from the iDisk.
Mark -
If I get the iphone 5 with plan and contract with 2 years or 3 can i pay $25 each mouth for just ulimited texting and 250 min of talking.
Ask the carrier instead of making yourself look like a fool by posting such a question in a user to user technical support forum.
-
I have a macbook pro with mountain lion and now so I can not synchronize my outlook calendar office 2011 for mac with ical and, therefore, with icloude. Can anyone help?
http://support.apple.com/kb/HT5922
If you want to mirror your desktop, see:
http://support.apple.com/kb/HT5404
Regards. -
After spending several hours sorting out Canon Pixma OSX problems here are my thoughts:
Canon 860 Series (Pixma 868) Printer Problems with OSX 10.8 (Mountain Lion) – links to Canon Support Site with Drivers and Software with install tips
Problem:
- New imac and MacBook Pro 2012 (OSX 10.8.2) had a problem using Canon Pixma 868 printer on network and would not scan or print using Canon Pixma software (Pixma MP Navigator 2.1 & Photo Print), which has advanced scanning and photo printing functions.
- When I connected the canon printer to my imac, OSX 10.8.2 automatically downloaded and installed drivers for Canon 860 series printer. I could then add the new printer (select ‘apple menu’ / ‘system preferences’ / ‘print and scan’ / “+”) and printer would work while connected via USB but could not get to print or scan over network wifi.
- The original Canon 860 Series CD does not work with 10.8 and the manual / online instructions did not make sense (as based on CD install).
Solution:
1) Install Canon Printer Drivers and Software (from official Canon site)
Go to canon support site, review FAQ, then download and install following Pixma 860 Series software & drivers for OSX 10.8 (links see below). The version I downloaded is in brackets but check for updated version. Full instructions are below.
Canon 860 Series Drivers & Software for OSX 10.8 Mountain Lion:
The base software and drivers needed for using Canon 860 Series on Mac OS X 10.8 (USB) are
1 Printer Driver
(Canon MX860 series CUPS Printer Driver Ver. 10.67.1.0 (03-Aug-2012))
2 Scanner Driver
(Canon MX860 series Scanner Driver Ver. 14.11.4a (03-Aug-2012))
3 Network Tool
(Canon IJ Network Tool Ver. 4.1.0 for Intel Mac (27-Dec-2012)
Canon Software for using advanced printing and scanning functions (while connected to network)
4 Solution Menu
(Canon Solution Menu Ver. 1.4.1 (27-Jul-2012 ))
5 MP Navigator EX
(Canon MP Nav EX Ver. 2.1.3 (02-Auf-2012))
6 Easy-PhotoPrint EX
(Canon Easy-PhotoPrint EX Ver. 4.1.6 (21-Jan-2013 ))
Canon Support (HK) – check your local site
http://www.canon.com.hk/en/download/main/index.do
Select Product and drivers from support site eg http://support-hk.canon-asia.com/
1. Choose a product category
Multifunctional Printers
2. Choose a product series
Pixma
3. Choose a product model
Pixma MX868
4. Choose type of document
Downloads or FAQ
If you have problems installing the software under 10.8, see the FAQ on Canon site. You will need to allow software installs from “unidentified developers by using “Control” Key or by changing your system preferences)
2) Check Canon Printer and Software Working while connected via USB
Once you have downloaded and installed drivers and software and restarted computer, check that the printer and Canon Pixma software (Pixma MP Navigator 2.1 & Photo Print) are working via USB. Open the Canon IJ Network Tool App (Applications / Canon Utilities /IJ Network Tool / Canon IJ Network Tool App) and make sure you can see the Canon MX 860 series (xx.xx.xx.xx.xx.xx) and that it shows the correct SSID Wifi settings (under the Canon IJ Network Tool App ‘Setup menu’). This is normally done as part of the automatic install but worth double checking
3) Add new network printer using ‘apple menu’ / ‘system preferences’ / ‘print and scan’ / “+”).
After you have checked USB printing turn off printer, unplug the USB cable and shutdown the Canon IJ Network Tool App.
Then turn the printer back on and wait 30s. Then add a new printer using ‘apple menu’ / ‘system preferences’ / ‘print and scan’ / “+”). Once you select “+” (add new printer), wait 10-30s for the Wifi Networked Canon MX 860 Series printer to appear in the new window eg Canon MX 860 series (xx.xx.xx.xx.xx.xx) (Kind: “Canon IJ Network”)
DO NOT ADD THE MX 860 SERIES BONJOUR SCANNER (the Bonjour Scanner is the built-in software, is not needed and often appears first on the add printer list). The Canon scanner can be accessed used through the MP Nav EX Ver. 2.1.3 software (which has much better functions)
You will now have two Printer Canon MX860 (USB) and Canon MX860 (Wifi / Network). Set the Canon MX860 (Wifi / Network) as default and test print and scan
If the Wifi Networked Canon MX 860 Series printer does not appear, check the printer and make sure that the printer can see the wifi network. On the printer select Menu / Settings / Device Settings / Lan Settings / WLAN Setting List. It should say WLAN Active, identify the SSID and have an IP address
If the printer can not see the Wifi Network, plug the USB cable back in, then open the Canon IJ Network Tool App (Applications / Canon Utilities /IJ Network Tool / Canon IJ Network Tool App). Make sure you can see the Canon MX 860 series (xx.xx.xx.xx.xx.xx) and that it has your SSID settings (under setup), if it has this info, restart the computer and the printer and try againHi, thaks for response, meant to post as a discussion (not question), wanted to save others time if they get the same problem
-
How to create a transport request with query and only with its structure.
HI guru,
how to create a transport request with query and only with its structure.transport request should not include any other query items like ( variables, conditions...etc)
thanks in advance.
venkataHi,
Goto RSA1 and then Transport Connection -> In SAP Transports select Object Types-> Query Elements -> Then select Query->Give Technical name of the query and then select for transfer. In the right side you can choose the components which you wanted to transport.
Regards,
anil -
Difference in File Adapter Read File as attachment and Use File streaming
Hi all,
As part of our POC we created a File adapter using the option Read file as attachment and File streaming we observed below things
1.When we are taking “Attachment” option in file adapter, Its able to archive, but not supporting to write data to different location(using fileadapter’s write operation.)
2.when WE are taking “ file streaming “ option in the adapter , Its not able to achive, but it writes data to different location(using fileadapter’s write operation.)
Can anyone know is this is a correct behaviour . If yes what is the reason .
Thanks
PhaniHi all,
As part of our POC we created a File adapter using the option Read file as attachment and File streaming we observed below things
1.When we are taking “Attachment” option in file adapter, Its able to archive, but not supporting to write data to different location(using fileadapter’s write operation.)
2.when WE are taking “ file streaming “ option in the adapter , Its not able to achive, but it writes data to different location(using fileadapter’s write operation.)
Can anyone know is this is a correct behaviour . If yes what is the reason .
Thanks
Phani -
Matrix with CFL and RecordSet with DoQuery
Hello Experts,
How to use Matrix with CFL and RecordSet with DoQueryHi Manish,
Refer to SDK sample on CFL at ...\SAP\SAP Business One SDK\Samples\COM UI\VB.NET\17.ChooseFromList
Go to SDK Help, Developer's Guide -> DI DPI -> Reference -> Overview -> Objects -> Recordset
see the Example "Recordset Operations sample" at the bottom of the page
HTH
Aravind -
Can't label files in bridge, and problem with starred files
I'm working with CS3 on saving raw files to jpegs, and I usually organize them by 5 starring my favorites as well as labeling them, and just in the last 2 days Bridge has been acting up and won't label the files. Also, it will 5 star them, but only about a 1/4 of them show up in the filter as being starred. Any ideas? I already checked my access, and I can read and write to them.... the only thing I can think of is that I ran a few updates a day or two ago.... help! this is getting really frustrating and slowing down my workflow...
http://forums.adobe.com/community/bridge/bridge_macintosh
-
How to read a C structure with string and int with a java server using sock
I ve made a C agent returning some information and I want to get them with my java server. I ve settled communication with connected socket but I m only able to read strings.
I want to know how can I read strings and int with the same stream because they are sent at the same time:
C pgm sent structure :
char* chaine1;
char* chaine2;
int nb1;
int nb2;
I want to read this with my java stream I know readline methode to get the first two string but after two readline how should I do to get the two int values ?
Any idea would be a good help...
thanks.
Nicolas (France)Does the server sent the ints in little endian or big endian format?
The class java.io.DataInputStream (with the method readInt()) can be used to read ints as binary from the stream - see if you can use it. -
hi,
anyone have code for SSL with NIO.
ThanksYou could start by searching this very forum for 'SSLEngine', & try Google too. Also have a look in your JDK samples.
Maybe you are looking for
-
Every now and then after prolonged usage by battery gets very warm, I am a battery app which also shows battery temperature, it is normally in the 25 degrees celcius but will spike to the high 30s, is this an issue to be concerned with? Solved! Go to
-
plz help me out iam not able to use my ipod i tried in all the possible ways to make it work but no use it indicates to connect to itunes and when i connect it to my pc it says your device is not recorgnised iam stuck with it am not able to use my ip
-
Personas button does not appear in HTML
Personas button does not appear in HTML Hi! I installed Personas 2.0 and finished most of the configuration. The Sliverlight component is working fine but when I switch to html component the personas button not appear. I did all the settings. User ha
-
Release Repetitive code in OT81
Hi All, Have 2 scenario; 1. Create Repetitive code in 0T81 and required 2 person to release the repetitive code 2. Copy repetitive code in OT81 only required 1 person to release. Regards to the above scenario ; When we create repetitive code in OT81
-
I have created a web design and integrated some simple Flash elements. I used Dreamweaver. One of my testers is getting an IE (IE 6) error (like the flash is not initially loading properly, but then it does). I have tried saving the Flash as version