How to direct contents of file to stdout?

Hello
I'm trying to get contents of a file to stdout.
The filename is "pins.txt", text consists of only one line
let's say "abc".
Here's what I wrote so far:
File inputFile = new File("pins.txt");
FileReader in = new FileReader(inputFile);
int c;
while ((c = in.read()) != -1)
And now what?.
How to get String from 'in' object?.
Cheers

        InputStream is = new FileInputStream("pins.txt");
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        for(int count = 0; (count = is.read(buffer)) >= 0;)
            os.write(buffer, 0, count);
        String fileContent = new String(os.toByteArray(), "UTF-8");Change the 'UTF-8' encoding parameter to the encoding used in your file.

Similar Messages

  • How to read contents of files that do not fall under public security group?

    Hi,
    I need to read the contents of a WCM based xml file that does not fall under public security.
    The process is like this:
    First the user makes chnages to the content.
    The workflow will be triggred based on the security group metadata that is associated with the content.
    Once the content is finally approved our workflow calls a custom idoc script.
    First we tried directly reading the xml contents from the idoc script which was still in the context of workflow. But since content item is still in workflow I was not able to read the changes. So I created a separate content publisher thread and read the DOC_INFO and checked for the dStatus value. If the value is RELEASED then I reading contents by calling ssIncludeXml idoc script.
    This was working fine for public content. But now the requirement is that all content cannot be public. Content authors should not be able to edit the content that does not belong to their group, So we created security groups (and roles) and are associating that groups to the relavent content.
    Beacuse of this change I am not not able to read the non public content. The call to DOC_INFO_BY_NAME service, which gives all the content files' metadata, is expecting the user to be logged in to give the details.
    I tried calling the CHECKIN service with sysadmin and captured the cookies returned by that service and use cookies for the DOC_INFO_BY_NAME service call. But the service call was faling. It is throing the 401 forbidden error with the message that user needs to be logged in to get the details.
    How to address this problem. Someone please help.
    Note: I also tried using ridc for this. I was able to get it working but since it is executing in the context of server ridc api is changing server's environment properties like HTTP_HOST, HTTP_CGIPATHROOT etc. It also seemed like system was becoming non functional after using ridc. When I called check-in the system metadata values like security group are no more loading. Not sure if ridc is the culprit here but worried that it might be causing this issue.
    Regards,
    Pratap

    Sorry, I posted too much details while posting this question. I was saying "not able to read *non* public content".
    Anyway, I was able to resolve the issue. I was able to authenticate with sysadmin credentials in the request to service using basic authentication and was able to read doc info with that credential.
    But I realized there is more than option for reading secure content.
    - I could set user name as sysadmin in the m_environment (if I am in the context of a service) and the call the DOC_INFO_BY_NAME service.
    - I can post an HTTP request to DOC_INFO_BY_NAME service with sysadmin credentials and do basic authorization via the connection. (This is what i have done successfully as of now )
    - I could add guest role to all security groups with R (read) privileges.
    I will look into all options and implement the one which is more apt.
    Regards,
    Pratap

  • How to view contents of file without opening the file?

    Does anyone know of a utility that will allow you to quickly view the contents - or a part thereof - of a file (particularly Word files) without having to open the file? I have thousands of files restored after a disk failure, but their filenames have been lost and replaced with sequential numbers. The only way of knowing the contents is to open the file, a tedious process for so many. I seem to recall seeing a shareware app that allowed this. Thanks for any help.
    MacBook Pro 17   Mac OS X (10.4.8)  

    Open the Script Editor in the /Applications/AppleScript/ folder and paste in the following:
    tell application "Finder"
    repeat with this_num from 1 to 5
    set the_item to item this_num of window 1
    set the_name to name of the_item
    set the_text to (read (the_item as alias) from 1 to 15)
    tell application "TextEdit"
    set text of document 1 to (text of document 1) & the_name & return & the_text & return & return
    end tell
    end repeat
    end tell
    Before running the script, place the folder containing the files in the frontmost Finder window; you may want to split the files between several different folders and process each folder before heading on to the next one. The numbers in blue can be customized as needed; the first one controls how many files the script will search on each run, and the other two define what part of the file will be searched. The output from a file which is in a format other than plain text may contain document formatting and other content which will look like random characters.
    (19999)

  • How to store content of file in a string

    Hi All :) ,
    i wanted to store all the content of a file say HTML file in a String ,please tell me how should i do that so that all the content from <HTML> to </HTML> copied to the string ..thanks :)

    ashish.escape wrote:
    Is this a right way ?It's not a good way, but I think that it will almost work. To make it work, try using a BufferedReader instead of a DataInputStream (which is deprecated for reading lines), like this:
    BufferedReader reader = new BufferedReader( new InputStreamReader( fis ) );
    while( (thisLine = reader.readLine() ) != null )
    ...Don't forget to close the reader after you're done.
    There are quite a few things "not good" about this code:
    * The exception handling is horrid - you may very well be hiding the real problem - try getting rid of the try/catch and simply declare your main method as 'public static void main(String[] args) throws Exception' - that will exit the application and print the full exception and stack trace to the console. I would make this change and run the application again before doing anything else.
    * Use a StringBuffer to append to, concatenating Strings is very slow.
    * It's not apparent why you even need to read a line at a time - it looks like you could just read the file into a buffer and append that to the StringBuffer without needing to worry about parsing it a line at a time, unless there is some processing that you're doing on each line that is not shown in this code snippet.
    As the first responder said, you should really read the IO tutorial here:
    http://java.sun.com/docs/books/tutorial/essential/io/

  • How to directly deploy lca files on adobe application server

    Hi,
    Can anybody tell me alternative way of deploying lca file on server without using import application feature from admin ui.
    Is ther anyway of deploying lca application directory on adobe configured jboss server.
    Please let me know how can i hard deploy lca application. I dont see applications in any of the folder on server when imported from adminui.
    Regards
    Sunil Gupta

    do you have Oracle application installed on another server?
    If yes, please run following in your browser and check the response. This is for 11.5.10
    http://hostname:port/configurator/oracle.apps.cz.servlet.UiServlet
    This is for R12
    http://hostname:port/OA_HTML/configurator/oracle.apps.cz.servlet.UiServlet
    You do not need to install oracle server on your custom application. You can directly access them by url.
    Thanks,
    Pankaj

  • How to remove contents of  file

    hi frnzs,
    i m storing my all output in a file,first time new file is created, and all data is stored, next time when i run again, that file is still there, i just want to remove all contents of it, when again my program runs.

    You can also do something like this:
    if (file.exists()) {
        file.delete();
    }But why do you want to delete the file when you are starting your application? Isn't it better to delete the file when the application exits? You can in that case call deleteOnExit() on the file after you have created it.
    Kaj

  • How to directly print PDF file(which is stored in SAP) in ABAP report?

    Hi experts,
    I searched SDN for printing PDF file but everything is about OTF to PDF and to use fm: CONVERT_OTF which is not the solution for my problem.
    I have to build ABAP report which will take the PDF file attached to SAP document (CV02N) and print it.So, which function module or program can I use to print the PDF file?
    Thank you very much.
    Kind regards,
    Danijela

    Dear
       this is the code for down load smartform for PDF format. its working properly
    2nd way is
    set your Acrobat Printer as your default printer
    when you print select printer as LOCAL
    then you will file dialog box for Naming PDF
    DATA  :  T_OTF          TYPE ITCOO OCCURS 0 WITH HEADER LINE.
      DATA  :  WA_CTRLOP      TYPE SSFCTRLOP.
      DATA  :  WA_OUTOPT      TYPE SSFCOMPOP.
      DATA  :  T_OTFDATA      TYPE SSFCRESCL.
      DATA  :  T_PDF_TAB      LIKE TLINE OCCURS 0 WITH HEADER LINE.
      DATA  :  V_FILESIZE     TYPE I.
      DATA  :  W_BIN_SIZE     TYPE I.
      WA_CTRLOP-GETOTF = 'X'.
      WA_CTRLOP-NO_DIALOG = 'X'.
      WA_OUTOPT-TDNOPREV = 'X'.
      CALL FUNCTION P_LV_FNAME
        EXPORTING
          OUTPUT_OPTIONS     = WA_OUTOPT
          USER_SETTINGS      = 'X'
          CONTROL_PARAMETERS = WA_CTRLOP
        IMPORTING
          JOB_OUTPUT_INFO    = T_OTFDATA
        EXCEPTIONS
          FORMATTING_ERROR   = 1
          INTERNAL_ERROR     = 2
          SEND_ERROR         = 3
          USER_CANCELED      = 4
          OTHERS             = 5.
      T_OTF[] = T_OTFDATA-OTFDATA[].
      CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          FORMAT                = 'PDF'
          MAX_LINEWIDTH         = 132
        IMPORTING
          BIN_FILESIZE          = W_BIN_SIZE
        TABLES
          OTF                   = T_OTF
          LINES                 = T_PDF_TAB
        EXCEPTIONS
          ERR_MAX_LINEWIDTH     = 1
          ERR_FORMAT            = 2
          ERR_CONV_NOT_POSSIBLE = 3
          OTHERS                = 4.
      DATA  :  LV_DOWN_FILE TYPE RLGRAP-FILENAME.
      DATA  :  LV_TEXT      TYPE STRING.
      CASE SSCRFIELDS-UCOMM.
        WHEN 'REPRUNMOLD'.
          CONCATENATE '(' SO_SCHDT-LOW '-' SO_PLANT-LOW ')' INTO LV_TEXT.
          CONCATENATE '\\lkdb01\FTP-Loadstar\0.PP_Planning\ZPP014\Run_Moulds\' SY-DATUM '-' SY-TIMLO '-' 'Running Mould' '-' LV_TEXT '.pdf' INTO LV_DOWN_FILE SEPARATED BY SPACE.
        WHEN  'REPLINESIT'.
          CONCATENATE '(' SO_SCHDT-LOW '-' SO_PLANT-LOW '-' SO_LINE2-LOW ')' INTO LV_TEXT.
          CONCATENATE '\\lkdb01\FTP-Loadstar\0.PP_Planning\ZPP014\Line_Situation\' SY-DATUM '-' SY-TIMLO '-' 'Line Situation' '-' LV_TEXT '.pdf' INTO LV_DOWN_FILE SEPARATED BY SPACE.
      ENDCASE.
      CALL FUNCTION 'WS_DOWNLOAD'
        EXPORTING
          BIN_FILESIZE            = W_BIN_SIZE
          FILENAME                = LV_DOWN_FILE
          FILETYPE                = 'BIN'
        IMPORTING
          FILELENGTH              = V_FILESIZE
        TABLES
          DATA_TAB                = T_PDF_TAB
        EXCEPTIONS
          FILE_OPEN_ERROR         = 1
          FILE_WRITE_ERROR        = 2
          INVALID_FILESIZE        = 3
          INVALID_TYPE            = 4
          NO_BATCH                = 5
          UNKNOWN_ERROR           = 6
          INVALID_TABLE_WIDTH     = 7
          GUI_REFUSE_FILETRANSFER = 8
          CUSTOMER_ERROR          = 9
          OTHERS                  = 10.
      IF SY-SUBRC <> 0.
        MESSAGE  'File not downloaded succesfully' TYPE 'I'.
        EXIT.
      ELSE.
        MESSAGE 'PDF File downloaded succesfully' TYPE 'I'.
      ENDIF.
    ENDFORM.                    " Print_PDF
    Rewards if useful.

  • How to edit the content.opf  file of a FXL EPUB?

    I'm exporting a fixed layout epub and I cannot find out where the content.opf file is and how to edit it.  I'm trying to do the same thing that was done here: Indesign CC 2014 Fixed Layout export
    Can anyone point me in the right direction? I've googled to no end!
    Thanks,

    Please follow these steps to edit your EPUB:
    1. Download Sigil https://code.google.com/p/sigil/downloads/list
    2. Open your EPUB in this editor.
    3. In the book browser view on your left, look up for content.opf file. Edit this file and save your EPUB.
    Regards,
    Pooja
    InDesign Engineering

  • How to save contents of two different rich edit box into single rtf file in windows 8.1 app

    Developer, I have requirement to save registration data into rtf file.. These can only be done by if I put rich edit box to fill the data.. Now if I am going to write the code for saving the data of different rich edit box into one particular file, it
    only saves the data of last rich edit box.. So plzz suggest that how can I save the contents of different rich edit box together into one rtf file.

    Ok Nishant, just did some quick research, since rtf file is unlike txt file, we cannot simply directly write some content to the rtf.
    You can try to find some third party code that can help you insert text into rtf file or you would like to load the content from rtf out to the richeditbox and merge them to one richeditbox and then save back to the file.
    You could like to see how to read/save rtf file sample from:
    RichEditBox class
    --James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Apple loops for garageband pack doesn't show the folder content (loops, files...)  in ableton live suite 8 library browser, but I can see all the loops in the folder from finder. how can i fix this? help please.

    apple loops for garageband pack doesn't show the folder content (loops, files...)  in ableton live suite 8 library browser, but I can see all the loops in the folder from finder. how can i fix this? help please.

    Thanks Barney, I tried that but all that comes up in Spotlight are the log files that show the file paths! I don't know how Steam works. Are all the files held by Steam on their server perhaps?

  • My laptop was stolen and with it my itunes, all of my music (including non-apple downloaded content) is still on my iphone 5, how can I transfer the files to my new laptop which is authorised to the same apple ID?

    my laptop was stolen and with it my itunes, all of my music (including non-apple downloaded content) is still on my iphone 5, how can I transfer the files to my new laptop which is authorised to the same apple ID?

    See this user tip for recovering the media from the iPhone: https://discussions.apple.com/docs/DOC-3991

  • How do I add a "file folder" to my TC so that I can save files directly to the TC?

    I am trying to figure out how I can add a "File Folder" to my TC so that I can save files directly to it? The only folder it displays is "Data" which is where my bac ups save...

    Double click on the "Data" folder in the Finder under the SHARED heading, and then click the gear icon at the top of the window and select New Folder.
    You can name this folder anything you wish and also create as many folders as you wish.
    If you are also using the Time Capsule drive for Time Machine backups, it is not really recommended that you "mix" regular files with Time Machine backups because there will be a struggle for space on the drive at some point.
    If you have plenty of free space on the Time Capsule drive, you may be OK with keeping a portion dedicated for regular files.

  • How do I move a file directly from the desktop to a folder in OX 10?

    I am new to Mac and the Mountain Lion software.  Having worked exclusively with PC operating systems, I am familiar with how to work with files in Windows, but am having trouble doing similar actions in OX 10.  How do I move a file directly from the desktop to a folder in OX?  Although this answer is likely in a video tutorioal (somewhere), I do not have the time to sit an arbitrarily watch generic OS videos that give a broad brush overview, without answering specific queries.  Any help out there?

    You might fun http://www.apple.com/support/macbasics/ to be of help to get used to doing things the Mac way.
    Allan

  • How to create a text file or XML file  and add content through  code into it...

    Hi Everyone,
    How to create a text file and add content through the code to the text file eform javascript ......orelse can we create a text file in life cycle designer...
    Else say how to create a new XML file through the code and how some content like Example "Hello World".

    You can create a text file as a file attachment (data object) using the doc.createDataObject and doc.setDataObjectContents:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.450.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.528.html
    You can then export the file with the doc.exportDataObject method:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.463.html
    This won't work with Reader if it hasn't been given the file attachment usage right with LiveCycle Reader Extensions.

  • How to create new XML file using retreived XML content by using SAX API?

    hi all,
    * How to create new XML file using retreived XML content by using SAX ?
    * I have tried my level best, but output is coming invalid format, my code is follows,
    XMLFileParser.java class :-
    import java.io.StringReader;
    import java.io.StringWriter;
    import javax.xml.transform.OutputKeys;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMResult;
    import javax.xml.transform.sax.SAXSource;
    import javax.xml.transform.sax.SAXTransformerFactory;
    import javax.xml.transform.sax.TransformerHandler;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import org.xml.sax.Attributes;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.XMLFilterImpl;
    public class PdfParser extends XMLFilterImpl {
        private TransformerHandler handler;
        Document meta_data;
        private StringWriter meta_data_text = new StringWriter();
        public void startDocument() throws SAXException {
        void startValidation() throws SAXException {
            StreamResult streamResult = new StreamResult(meta_data_text);
            SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
            try
                handler = factory.newTransformerHandler();
                Transformer transformer = handler.getTransformer();
                transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                handler.setResult(streamResult);
                handler.startDocument();
            catch (TransformerConfigurationException tce)
                System.out.println("Error during the parse :"+ tce.getMessageAndLocation());
            super.startDocument();
        public void startElement(String namespaceURI, String localName,
                String qualifiedName, Attributes atts) throws SAXException {
            handler.startElement(namespaceURI, localName, qualifiedName, atts);
            super.startElement(namespaceURI, localName, qualifiedName, atts);
        public void characters(char[] text, int start, int length)
                throws SAXException {
            handler.characters(text, start, length);
            super.characters(text, start, length);
        public void endElement(String namespaceURI, String localName,
                String qualifiedName) throws SAXException {
            super.endElement("", localName, qualifiedName);
            handler.endElement("", localName, qualifiedName);
        public void endDocument() throws SAXException {
        void endValidation() throws SAXException {
            handler.endDocument();
            try {
                TransformerFactory transfactory = TransformerFactory.newInstance();
                Transformer trans = transfactory.newTransformer();
                SAXSource sax_source = new SAXSource(new InputSource(new StringReader(meta_data_text.toString())));
                DOMResult dom_result = new DOMResult();
                trans.transform(sax_source, dom_result);
                meta_data = (Document) dom_result.getNode();
                System.out.println(meta_data_text);
            catch (TransformerConfigurationException tce) {
                System.out.println("Error occurs during the parse :"+ tce.getMessageAndLocation());
            catch (TransformerException te) {
                System.out.println("Error in result transformation :"+ te.getMessageAndLocation());
    } CreateXMLFile.java class :-
    Sax.startDocument();
    Sax.startValidation();
    Sax.startElement("", "pdf", "pdf", new AttributesImpl());
    Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());          
    String xmp_str = new String(meta_data.getByteArray(),"UTF8");
    char[] xmp_arr = xmp_str.toCharArray();
    Sax.characters(xmp_arr, 0, xmp_arr.length);
    Sax.endElement("", "pdf", "pdf");
    Sax.endValidation();
    Sax.endDocument();
    Sax.endElement("", "basic-metadata", "basic-metadata");* In CreateXMLFile.java
    class, I have retreived the xml content in the meta_data object, after that i have converted into character array and this will be sends to SAX
    * In this case , the XML file created successfully but the retreived XML content added as an text in between basic-metadata Element, that is, retreived XML content
    is not an XML type text, it just an Normal text Why that ?
    * Please help me what is the problem in my code?
    Cheers,
    JavaImran

    Sax.startDocument();
    Sax.startValidation();
    Sax.startElement("", "pdf", "pdf", new AttributesImpl());
    Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());          
    String xmp_str = new String(meta_data.getByteArray(),"UTF8");
    char[] xmp_arr = xmp_str.toCharArray();
    Sax.characters(xmp_arr, 0, xmp_arr.length);
    </code><code>Sax.endElement("", "basic-metadata", "basic-metadata");</code>
    <code class="jive-code jive-java">Sax.endElement("", "pdf", "pdf");
    Sax.endValidation();
    Sax.endDocument();     
    * I HAVE CHANGED MY AS PER YOUR SUGGESTION, NOW SAME RESULT HAS COMING.
    * I AM NOT ABLE TO GET THE EXACT OUTPUT.,WHY THAT ?
    Thanks,
    JavaImran{code}

Maybe you are looking for

  • Ipad2 with wifi WEP connectivity problems

    Please anybody could help me to get connected my ipad2 to a wifi wep. The ipad recognizes the wifi but not able to connect... Thanks

  • How can I o this code

    Write a java class called "Ship". Ship can have id, number of sailors, and speed. -     Apply information hiding / encapsulation in defining Ship data members. -     Provide appropriate number constructors for this class. -     Override toString meth

  • Costing Dimensions..!!!

    Hi All, We are presently working with SRM V4.0/EBPV5.0 with only Cost centres as defined attributes for every User against his position ID attributes without any budget control. Now the Client wants to implement the following Costing Dimensions with

  • Can't install Plug ins

    Hello, I've been trying to install BorderFX but no success. The installation well through just fine but I don't see it in File>Export. It says No Plug-ins Installed. The only guide on BorderFX's support page regarding the installation process is to f

  • Unable to execute pivot table option

    Hi group, We are running OBIEE version 10.1.3.4.1. We use OBIEE with APCC (Advance Planning Command Center). When some clients (PC's) try to run Pivot Table using next option (Answers--> Shared Folders -->Other --> Resource Utilization --> Modify -->