How to display the contents of a text file on the command line?

I realize I need to utilize classes from the java.io.* package, but I don't know which ones to use exactly. This is what I would like to do in a nutshell:
public static void main(String[] args) throws IOException {
File inputFile = new File( <path to the file>);
// code that reads data from the above file and is able to
// append it to  a string object or display it on the command
// line (System.out.println)
}Thanks for your time!

It's pretty easy. Here's a little example that reads a file, stores it in a string, and prints it to the command line.
import java.io.*;
public class OpenFile {
     public static void main(String args[]) {
          try {
               File fileToOpen = new File("something.txt");
               FileReader fileIn = new FileReader(fileToOpen);
               BufferedReader br = new BufferedReader(fileIn);
               String fileContent = new String();
               String line;
               while ((line = br.readLine()) != null) {
                    fileContent += line + "\n";
               System.out.println(fileContent);
               br.close();
          catch (IOException e) {
               System.out.println("Exception: " + e);
}Good luck,
Alex

Similar Messages

  • How can hide the command line of a t.code in the portal

    Dear Experts.
    I have the following doubt:
    How can hide the Command Line of a Report that is called with a T.Code in the portal?
    Attach Image:
    [Image T.Code|http://www.freeimagehosting.net/uploads/eab3b6a03c.jpg]
    When I created a service using the T.Code SICF for the T.Code , I can hide buttons and the filed command line  using
    ~webgui_simple_toolbar
    ~singletransaction
    ~NOHEADEROKCODE
    With notes 1010519, "SAP GUI for HTML: Simplified Title Area Without Menu and OK Code" and 959417.
    But the problem is that when I create the service in the T.Code SICF, I also have that create an Iview IAC in the portal.
    The Question is : How can hide this fields and buttons if I want Publish the T.code using an Iview Transaction in the portal?
    In this moment I have used the two options:
    1 option) I created a service using the t.Code SICF for my Transaction and I also created an Iview IAC in the portal for call the service.
    RESULT:
    SAP Web Application Server
             500 Connection timed out
            Error: -5
           Version: 7000
           Component: ICM
           Date/Time: Sat Jun 12 20:26:39 2010 
           Module: icxxthr_mt.c
           Line: 2698
           Server: xyxab...
    Error Tag: {-}
    Detail: Connection to partner timed out after 60s
    2)  created an Iview Transaction  in the portal and  call my transaction.
    RESULT.
    [Image T.Code|http://www.freeimagehosting.net/uploads/eab3b6a03c.jpg]
    But not can hide the field Command Line and other buttons.
    I think that the command :
    ~webgui_simple_toolbar
    ~singletransaction
    ~NOHEADEROKCODE
    Only can be used if I create a service using the T.Code SICF .
    Best Regards
    Carmen.

    Hi Carmen,
    The bottom line is that this cannot be done for transaction iviews without modifying the standard webgui service in SICF, which is probably not a good idea (since it affects everyone using SAP GUI for HTML). (You could hack the appintegrator to add the ~webgui_simple_toolbar parameter to the transaction URL template in the portal, but again its not a recommended thing to do ...). Better to create an IAC service in SICF with ~webgui=1 where you set the required appearance using an appropriate value for ~webgui_simple_toolbar, and then create an IAC iview to point at this service.
    You can even override the ~transaction value configured in the new service in individual IAC iviews by entering the appropriate value in the application parameter of the iview, for example:
    ~okcode=/nSU01
    And you can pass parameters in the same way:
    ~okcode=/nSU01 USR02-BNAME=xyz;USREFUS-USERALIAS=abc;
    By the way, it would not be recommended to create a URL iview to access an IAC, since you are likely to encounter session management issues in this scenario - better to use an IAC iview.
    Regards, Rory

  • How to break the command line in SAP scripts

    Hi,
      Can any one Please guide me how to continue the command line( /: ) of SAP SCPRIPT into multiple lines.
    Regards
    Kiran

    Hi Kiran,
    U can continue in the same line itself by pressing SHIFT+F8
    If u want it in the next line then u can give space in the tag column.
    Thanks,
    Vinod.

  • How To Parse The Command Line?

    Hello,dear. When I writing a C/S mode application,which performing download and upload files between the FTP server and the clients, I encountered the problem of parsing the command line.
    I intend to download file from the server side ,using this following format ,which is composed by four arguments:
    ftp>receive server's IPaddress portnumber filename
    The problem is I don't know how to parse the command line and store them to some objects and using it.
    I'm right here waiting for the nice problem-shooter.
    Thanks for reading my poor expression.

    In your console application main class
    public static void main(String[] args)
    // code
    args is a sting array with the command
    line itemsI think you missed the point or forgot the ":-)". This is the "Socket", not the "New to Java" forum.

  • How to display the blank lines in between the message using SO_NEW_DOCUMENT

    Hi,
    I want to display the blank lines in between the paragarph of message using the function module  SO_NEW_DOCUMENT_ATT_SEND_API1.
    Regards
    Nagendra

    Hi Rajesh,
    Try using this code:
    CLASS: cl_abap_char_utilities DEFINITION LOAD.
    data: lf TYPE C VALUE cl_abap_char_utilities=>CR_LF.
    move lf to wa_lines.
    append wa_lines to li_lines.
    Hope this helps!
    Regards,
    Saumya

  • How to hide the command line arguments from solaris process

    Hi All,
    When I execute a JAR application from a java file using the Runtime.getRuntime, the command line arguments (user ID and Password details) which I passed for executing the application displayed on Solaris process (ps -ef).
    Could anybody please help me, how can I hide either the process or the command line arguments from the Solaris process?
    I cannot pass any asterix or any special character in place of password, because the executing application doesn't have any functionality to retreive the password which send as asterix characters.
    Please help me
    SumodeV

    Thanks for all the response.
    I have created a design and implement the functionality which executes the JAR application in Solaris environment without showing any details in the process details.
    I have used the Java Reflection method, which invokes the JAR application. I am sharing the details here for all those who looking for it.
    1, Inside the Customer application [Jar File is running for it], collect the necessary session details [Using System.get property method]
    2, Create an independent Java file, which should be used to invoke the JAR application
    3, Create the ProcessBuilder object and use a command - execute the Java file [a wrapper code] using normal Java command
    4, Pass the necessary session details to the ProcessBuilder using the environment() function.
    5. Collect the environment values in the independent Java file (Which was invoked by ProcessBuilder) and set details for its environment using System.setProperty.
    6, Use reflection technique to invoke the JAR plugin [which you want to run]. You can use the standard Java functionality to read the MANIFEST file of JAR and load the main class using URLClassLoader.
    7, Invoke the main method of the JAR file, which run the JAR application in Solaris window
    This solution will make sure that the process cannot display any session details in the Solaris Environment.
    Note: Use String[] array while create the command. Otherwise the JAR application cannot pop-up.
    Regards
    Sumode

  • How to uninstall the command line tools?

    I installed the command line tools in Xcode 4.5 from the preferences : downloads : command line tools.
    If i want to uninstall this component, what should I do?
    PS:
    I saw an answer in the Apple Support Communities about how to uninstall the Xcode 4.3 and later versions.
    This is the original: " If You want to uninstall completely XCode go to launchpad and push Xcode icon for two
    seconds, so click on the upper left checkbox.".
    I don't know what means "push Xcode icon for two seconds, so click on the upper left checkbox".

    There is no easy way to uninstall the command line tools. The following article has a script to uninstall them:
    You Don’t Need The Xcode “Command Line Tools”
    Read the comments in the article. I have not tested the script, but this is the first result when searching Google for "xcode 4.5 uninstall command line tools".

  • How to get the command line interface for WRT160NL router

    hi,
    How can I get the command line interface for WRT160NL router. please suggest.

    If you’re trying to access the web-based interface of your router, just use its default IP address (192.168.1.1). The Username is left blank and the Password is "admin". Here’s a quick link on how to do that.

  • How to display the multiple lines text in a single - String, StringBuffer

    Hi,
    I have a textarea field named Decription which contains more than one line seperated by new line.I need to display those five lines in a single text without breaking. Is it possible? I am getting ArrayIndexOutOfBoundsException while i reached to the end of the line. Plz help me how to align the below code so that i can display the lines as a single line in my excel sheet.
                        if(op.getDescription()!=null)
                            String[] oppDescs = op.getDescription().split("\n");
                            StringBuffer sb = new StringBuffer();
                            for(int i1=0; i<=oppDescs.length-1;++i1)
                                *writeFile(sb.append(oppDescs[i1]), valueWriter);*
                         } else {
                            writeFile(op.getDescription(), valueWriter);
    private void writeFile(java.lang.Object value,PrintWriter valueWriter)
            if(value!=null)
                valueWriter.print(value);   
        }Thanks and Regards

    previous was java1.5
    heres a 1.1 - 1.4 version
    String[] oppDescs = op.getDescription().split("\n");
    StringBuffer sb = new StringBuffer();
    for(int i = 0; i < oppDescs.length : i++){
      sb.append(oppDescs);
    sb.append( '\t' );
    writeFile(sb.toString(), valueWriter );Edited by: simon_orange on 31-Oct-2008 13:02                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to display html content in output text in adf

    Hi ADF Experts,
    I have a requirement like ,one of my function is generating this below html,
    I wan't to render in output text
    <span>d</span><del style="background:#ffe6e6;">f</del><span>df</span><del style="background:#ffe6e6;">d</del><ins style="background:#e6ffe6;"> </ins><span>f</span><ins style="background:#e6ffe6;">gfgfg</ins>
    Please help.

    Thanks Puthanampatti,
    with escape property in outputtext it is working now.

  • How to Use Associated App to open a file in Linux command line?

    Hi all,
    I know in windows i call always run:
    Runtime.exec("start aPicture.jpg");in order to use the default picture viewer to view the pictures
    Runtime.exec("start aEmail.eml");in order to use the default email viewer to view the .eml file
    is there a simular command in linux as well? does it depend on different distributions as well?
    thank you.

    is there a simular command in linux as well? does it
    depend on different distributions as well?In linux it's different because the handling is done by the desktop environment. KDE has it's own file associations and Gnome has it's own. There might be some way to start a file like that, but you first need to see which DE is installed (if any) and start it using that DE's method.
    But I don't know how to do it, even though most likely it's possible.
    Sincerely,
    Jussi

  • How to read the content of a text file (by character)?

    Guys,
    Good day!
    I'm back just need again your help. Is there anyone knows how to read the content of a text file not by line but by character.
    Please help me. Thank you so much in advance.
    Jojo

    http://java.sun.com/javase/6/docs/api/index.html
    package java.io
    InputStream.read(): int
    Reads the next byte of data from the input stream.
    Implementation:
    InputStreamReader
    An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.

  • HOW TO DISPLAY THE TEXT ON A PARTICULAR PAGE IN SAPSCRIPTS

    HI,
       HOW TO DISPLAY THE TEXT ON A PARTICULAR PAGE IN SAPSCRIPTS?

    in ur script main window
    /: IF &TTXSY-PAGE& = 15.              
    ur text or standard text           
    /: ENDIF.                             
    use this.
    hope it helps if any issues revert back

  • How to display the text as a Bold in the Text Element of a Smart Form

    Hi,
    I created one Smart Form.
    In that i created the Text element.
    I provide some data also in that.
    It is coming as a MS WORD.
    I executed my smart form.
    Customer Number:  &WA_KNA1-KUNNR&
    it display the data of the particular customer.
    But i need to display the Customer Number as BOLD or else Increase the Size.
    For this also I created one SMARTSTYLE.
    In that I created the Paragraph and Character Formats also.
    Now i assignee that SMARTSTYLE in the Output Option Tab of the Text Element also.
    But i unable to get the CUSTOMER NUMBER in Bold.
    In MS WORD we have BOLD button.
    I selected the Text and Press the BOLD button. At that time it is Highlighted.
    Whenever i press the SAVE Button.
    Then it is not saved with BOLD.
    It is coming in Normal Format.
    In the ECC 6.0.  I am unable to get the Text as a BOLD.
    This text Element is like a MS WORD.
    Can you please tell me how to display the Data with BOLD. please tell me. I am unable to get that one.
    Thank You.
    Regards,
    B. Krishna.

    Hi,
    Check where u have given BOLD. In character Format or in Paragraph format.
    In SMART FORM,
    1. Change to OLD EDITOR if u are confused with the new one.
            (This can be done by clicking the button left to new editor ).
    2. If it is PARAGRAPH FORMAT,
               Give the name of paragraph format in the editor.
                P1         &WA_KNA1-KUNNR&
        If it is CHARACTER FORMAT,
                             <C1> &WA_KNA1-KUNNR&
    Thanks,
    Nithya.

  • How to display the content of a region on a different page

    Hello,
    Does anyone knows how to display the content of a region on an other page. I try to make page that displays content that resides somewhere else in my portal, so I can give a summarization of some hot topics. I really want to display the whole content of some regions (not a display with custom search).
    Thanks a lot,
    Hans

    Set that page as portlet, include it in a region in another page and in the edit defaults decide which regions you want to display.
    Mere.

Maybe you are looking for