Reading a file in and storing it as a string

I need help with reading the contents of a .txt file in and saving the whole thing (including format) as a string so that I can then use a while loop to go through one character at a time. I know that there is an incredibly easy way to do this iI just can't think of it right now. Thanks.

I am really bad with processing files. I don't know
how to do what I want. I get null when I do this:
while ((text = in.readLine()) != null) {
text += in.readLine();
System.out.println(text);
while ((text = in.readLine()) != null) {
    do something with text, but DON'T call readline again
    maybe just System.out.prinln(text); for now to make sure you're getting something
} If you never get into the body of the loop, then the file is empty.

Similar Messages

  • Need to read text file content and have to display it in multiline text box

    dear all,
    Need to read text file content and have to display it in multiline text box.
    actually im new to file handling. i have tried up to get_line and put_line.
    in_file := TEXT_IO.FOPEN ('D:\SAMPLE.txt', 'r');
    TEXT_IO.GET_LINE (in_file,linebuf);
    i dont know how to assign this get_line function to text item
    pls help me in this regards,

    Simply write:
    in_file := TEXT_IO.FOPEN ('D:\SAMPLE.txt', 'r');
    TEXT_IO.GET_LINE (in_file,linebuf);
    :block2.t1 := chr(10)||:block2.t1||chr(10)||linebuf;
    chr(10) --> is for new line character

  • UDF for reading a particular line and storing the value in a variable

    Hi Experts,
    I am reading entire file content in single feild in source data type.I want to write a UDF to seach for a particular pattern(say :25: and store the value after it i.e  34535764778 detination for further use).
    EX: My  sample file and its  has feilds like
    point assured
    Thanks

    Hi since u are using a single field only then u dont need to use any advanced function
    Wel because if u see the formation of the queue u wil find the the whole data is under one context.. and there are not more context changes
    Convert the string to an array and progressively u can check for the four checks if the a<i>=:
    then a[i+]=2 then a[i]=5 and a[i+] =: and then substring the next 7-8 chrac.. hope u understand
    If this also doesnt work wel then u will have to use the Pattern class in Java
    By the way remember that the substring value cant be retained for the next instance of mapping
    Hope u have that in mind...
    Rgds
    Aditya

  • UDF to read a file name and use some of its contents to map fields in target.

    I have a scenario where I need to take the month and year from the file name and map it to suitable fields in the target. Ex - filename_apr2014 from this i should be able to read the month and year and map it. How to do this? I tried the udf -
    public String getFileName(Container container){
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    String ourSourceFileName = conf.get(key);
    return ourSourceFileName;
    got this error while testing the mapping -
    Runtime exception when processing target-field mapping /ns0:MT_<<>>_Output/I<<>>; root message: Exception:[java.lang.NullPointerException: while trying to invoke the method com.sap.aii.mapping.api.DynamicConfiguration.get(com.sap.aii.mapping.api.DynamicConfigurationKey) of a null object loaded from a local variable at slot 2] in class <<>> method getSourceFileName[com.sap.aii.mappingtool.tf7.rt.Context@5b04fc0f]
    See error logs for details  

    Hi Satish - You declared "conf" twice.
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    UDF -
    String filename    = "";
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create( "http:/"+"/sap.com/xi/XI/System/File","FileName");
    filename = conf.get(key);
    return filename;
    And did you define the variable slot 2 in any of your UDF's?
    The above UDF return the filename and you should handle the sub string later..

  • Read a file content and copy to another Diectory

    I wanted to do the following
    1-read a file from dir
    2- read the content of the file
    3- if the file contains zeros
    exit from this file and go to read next file
    else
    do some calculations
    i read a file and its contents and found zeros in the contents, so how can i say in the code to go to next file..
    any help please

    It depends on your code, but most likely using "return":
    //pseudo code
    while(moreFiles) {
      parseFile(file)
    void parseFile(File file) {
      while(moreContentToRead) {
        if(foundZero) {
          return;
    }

  • How to read a file name and send it a particular reciever

    Hi,
    I have a scenario, where i am receiving a a file and based on the file name i have to decide who is the receiver and send it to that particular receiver.I do not have to do any mapping.
    can someone suggest me how can I achieve this.
    Thanks in advance.

    HI This may help you.Let me know if not.
    Step by Step Guide: XML File 2 XML File Scenario: Part I
    Step by Step Guide: XML File 2 XML File Scenario: Part II
    Converting XML to PDF using XI
    Introduction to simple(File-XI-File)scenario and complete walk through for starters(Part1)
    Introduction to simple (File-XI-File)scenario and complete walk through for starters(Part2)
    "JAVA MAPPING", an alternate way of reading a CSV file
    Dynamic File Name using XI 3.0 SP12 Part - I
    Dynamic file name(XSLT Mapping with Java Enhancement) using XI 3.0 SP12 Part -II
    Push Data to MVC Architectured application using XI
    How to send any data (even binary) through XI, without using the Integration Repository
    XI in the role of a FTP
    The specified item was not found.
    The specified item was not found.
    The specified item was not found.
    The specified item was not found.

  • Read only file system and Problems witth pacman -S

    Hi im a newbie at Arch, and i have 2 problems...
    1) When I log in as a root user i can't modify any of the configuration files cause i only have a " Read only file System" does anyone know how  I can  change this cause im sick of using my live cd to modify the files i need to change..
    2) I have problems with pacman -S it says " Unable to lock database if you're sure pacman is not already running you can remove /tmp/pacman.lck"
    when i do rm /tmp/pacman.lck it says that it can't be done cause the file doesn't exist.. and Im sure that my dhcp and dns is working fine... (just in case of any wonder)
    Well if someone could help me i really would appreciate it
    thanks

    # <file>      <dir>           <type>     <options>           <dump>      <pass>
    none                 /dev/pts        devpts     defaults               0          0
    none                 /dev/shm        tmpfs      defaults           0          0
    /dev/cdrom           /mnt/cd          iso9660   ro,user,noauto,unhide  0          0
    /dev/dvd             /mnt/dvd         udf       ro,user,noauto,unhide  0          0
    /dev/fd0         /mnt/fl          vflat     user,noauto            0          0   
    /dev/hda6          swap            swap      default                0          0
    /dev/hda5/            ext3        defaults      0  0
    /dev/hda7/mnt/windows vfat  rw,usev,auto,umask = 000 0 0
    fsck -fC /dev/hda5 didnt work it said... "Error while executing fsck.ext3 for /dev/hda5

  • Programmatically read .rpt file, datasource and write it to word using ..

    I am using Crystal Reports 2008. The default editable rtf export format is tab based, really not useful for table formatted data.
    I would like to read rpt file along with data (e.g. saved xml source data) and write it to ms word format using com objects. Is this possible? If yes and supporting tutorial  or information.
    2nd: Is there any available ready software/tool to a true word format conversion?
    Thanks in advance.

    I would like to read rpt file along with data (e.g. saved xml source data) and write it to ms word format using com objects. Is this possible? If yes and supporting tutorial or information.
    - Export to XML(?)
    Sample; vbnet_win_export.zip at [this|http://wiki.sdn.sap.com/wiki/display/BOBJ/CrystalReportsfor.NETSDK+Samples] link.
    Developer Help files:
    https://boc.sdn.sap.com/developer/library
    [Crystal Reports for Visual Studio 2005 Walkthroughs|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/2081b4d9-6864-2b10-f49d-918baefc7a23]
    Above will apply to your version of CR and .NET also.
    Is there any available ready software/tool to a true word format conversion?
    - Not from SAP. Perhaps some 3rd party software(?).
    Oh, and the wiki [Available Export Formats, Crystal Reports 9.1 to Crystal Reports 2008|http://wiki.sdn.sap.com/wiki/display/BOBJ/AvailableExportFormats%2CCrystalReports9.1toCrystalReports+2008] may be good to have also.
    - Ludek

  • How to read Properties file once and access through the entire application

    HI All,
    I want to read properties file only once and want to access the property file values in entire application (like i want to access it in a ordinary class)

    Please do not double-post. Stick with one thread:
    http://forum.java.sun.com/thread.jspa?messageID=9678612

  • Siri Question - Voice Files Sent and Stored to Apple Server

    I have read online that when we use Siri, the voice file is sent to Apple and is stored for 2 years for analysis and improvement to Siri functionality.  My question is in regards to the voice to text functionality.  When I click on the microphone on the keyboard to do voice to text, are these files considered Siri files and are also stored on the server?  Or is it when I'm using Siri, holding down the home button, to text someone or look up when movies are showing nearby, is it those files that are being stored?
    I'm not sure if there is a difference between the voice to text vs. holding the home button for Siri and whether the files being sent to Apple are treated any differently.  Thanks...

    Gods this forum is neglected. Oracle where are you guys? Pretty lame effort on helping out the workers. I know use TARs and all that but why have a forum if you don't support it?
    Anyways. It seems that if you want your clients to be able to save email in a PST then you could do the Oracle/MS suggested method of not saving sent items and using a rule to push em into a PST. However that is pretty lame for a rollout and far to manual.
    You can however create a com add-in to do this. Here are some promising links on getting your sents in a PST. I am hopefully going to get one of these done so I'll share if that happens. I am still interested in alternative solutions for sent items to PST or automating client side rules in outlook.
    com addin for sent items!
    http://www.kbalertz.com/Feedback_316983.aspx
    Here is a discussion group that is actually supported by the vendor and good for all things Outlook (and therefore lots of connector type issues or work arounds).
    http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.outlook.installation&lang=en&cr=US

  • Iphoto - how are the photo files managed and stored ?

    I am one of those who migrated from the PC to this wonderfull world of the Mac. So please excuse my PC based way of thinking. 
    I have many thosands of photos, (aprx. 8,000 +++ )
    I used to organized my photos on an external hard disk and and I would create folder that would hold a group of photos; for example (A folder labeled "Vacation on New York" will hold all the photos for that event)
    Now on my iMac, I could import all the photos on that folder and create an event on iphoto called "Vacation on NY"
    The only question I have is where do those file phisically go to?  Where are those  files with their names and extensions?  What folder or directory do they go to once I import them into iphoto?
    I need to know this so that I could get a back up and know how to manage the files.
    Also...
    I would like to know how can I close all events at once.
    Thank you in advance for all the explanations......

    The files are copied into the iPhoto Library which is in your Pictures Folder.
    Most Simple Back Up
    Drag the iPhoto Library from your Pictures Folder to another Disk. This will make a copy on that disk.
    Slightly more complex:
    Use an app that will do incremental back ups. This is a very good way to work. The first time you run the back up the app will make a complete copy of the Library. Thereafter it will update the back up with the changes you have made. That makes subsequent back ups much faster. Many of these apps also have scheduling capabilities: So set it up and it will do the back up automatically. Examples of such apps: Chronosync or DejaVu . But are many others. Search on MacUpdate
    By way of explanation:
    The iPhoto Library  is a Package File. This is simply a folder that looks like a file in the Finder. This is to protect the iPhoto library because many users were inadvertently corrupting their library by browsing through it with other software or making changes in it themselves.
    Want to look inside?
    Go to your Pictures Folder and find the iPhoto Library there. Right (or Control-) Click on the icon and select 'Show Package Contents'. A finder window will open with the Library exposed.
    Standard Warning: Don't change anything in the iPhoto Library Folder via the Finder or any other application. iPhoto depends on the structure as well as the contents of this folder. Moving things, renaming things,, deleting them or otherwise making changes will prevent iPhoto from working and could even cause you to damage or lose your photos.
    To use an editor with iPhoto: You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. This is the only way that edits made in another application will be displayed in iPhoto.
    To use the files in other apps, upload them etc
    There are many, many ways to access your files in iPhoto:   You can use any Open / Attach / Browse dialogue. On the left there's a Media heading, your pics can be accessed there. Command-Click for selecting multiple pics.
    (Note the above illustration is not a Finder Window. It's the dialogue you get when you go File -> Open)
    You can access the Library from the New Message Window in Mail:
    There's a similar option in Outlook and many, many other apps.  If you use Apple's Mail, Entourage, AOL or Eudora you can email from within iPhoto.
    If you use a Cocoa-based Browser such as Safari, you can drag the pics from the iPhoto Window to the Attach window in the browser.
    If you want to access the files with iPhoto not running:
    For users of 10.6 and later:  You can download a free Services component from MacOSXAutomation  which will give you access to the iPhoto Library from your Services Menu.
    Using the Services Preference Pane you can even create a keyboard shortcut for it.
    For Users of 10.4 and 10.5 Create a Media Browser using Automator (takes about 10 seconds) or use this free utility Karelia iMedia Browser
    Other options include:
    Drag and Drop: Drag a photo from the iPhoto Window to the desktop, there iPhoto will make a full-sized copy of the pic.
    File -> Export: Select the files in the iPhoto Window and go File -> Export. The dialogue will give you various options, including altering the format, naming the files and changing the size. Again, producing a copy.
    Show File:  a. On iPhoto 09 and earlier:  Right- (or Control-) Click on a pic and in the resulting dialogue choose 'Show File'. A Finder window will pop open with the file already selected.    3.b.
    b: On iPhoto 11 and later: Select one of the affected photos in the iPhoto Window and go File -> Reveal in Finder -> Original. A Finder window will pop open with the file already selected.

  • Reading a file and changing one part of the file

    I am trying to read a file and then I want to change the first value on each line. The file I am reading is a .HEADER file. Which is just read in notepad I am just opening this like a txt file. I get no say at all how this file is created originally
    I want to change the value on the first line the a new title plus the ext .dat. The file is below. This stays the same format just with different values.
    ECG000 1 171 26112 9:14:56 23/04/2002
    ECG000 8 43(0) 8 127 79 -24066 0 AED trace
    I want to change the ECG000 to a new value eg Pat1.dat on the first line and Pat1 on the second line. When I read this file in and output to the dos window I get ECG000 0 0 0 and that is it. Any ideas why this is happening and how I can replace the values in the file??
         private void FileExt() throws IOException
              System.out.println("In function");
              BufferedReader br = new BufferedReader(new FileReader("c:\\Projects\\FirstSupport\\ECG000.HEADER"));
              String s;
              Vector data = new Vector();
              ECGFile = new FileWriter("c:\\Projects\\FirstSupport\\ECG.txt",true);
              System.out.println("Reading the file");
              while ((s = br.readLine()) != null)
              data.add(s);
              System.out.println(s);
              System.out.println("Finished");
              String label = s.substring(0, s.indexOf(" "));
              System.out.println(label);
              String newLabel = (label+".dat");
              System.out.println(newLabel);
         }

    I think this is what you're looking for:     private void FileExt() {
              java.util.List data=new ArrayList();
              String s;
              try {
                   BufferedReader br=new BufferedReader(new InputStreamReader(
                        new FileInputStream(new File("ECG000.HEADER"))));
                   while ((s = br.readLine()) != null)  {
                        data.add(s);
                        System.out.println(s);
                   br.close();
              catch (FileNotFoundException fnfe) {
                   System.out.println("Input file not found");
                   return;
              catch (IOException ioe) {
                   ioe.printStackTrace();
                   return;
              ListIterator li=data.listIterator();
              try {
                   PrintWriter ECGFile=new PrintWriter(new FileOutputStream(
                        new File("ECG.txt")));
                   while(li.hasNext()) {
                        s=(String)li.next();
                        if (s.substring(0, 6).equals("ECG000")) {
                             s="Pat1.dat"+s.substring(6, s.length());
                        ECGFile.println(s);
                   ECGFile.close();
              catch (FileNotFoundException fnfe1) {}
         }Mark

  • A need a function module to read a file and write back into it

    Hello ,
    My requirement is to provide the path to a file , read the file contents and then write back to it.
    Thanks,
    Mridu.

    Hi ,
    Use combination of these three FM's , A nice documentation is given for them by SAP .
    1.)  F4_FILENAME
    2.) GUI_UPLOAD
    3.) GUI_DOWNLOAD
    revert back if any queries
    reward points if helpful

  • Can I save and read text files on a server that I host?

    Hello everyone,
    I am a java hobbiest. I was wondering if I set up my own server, running out of my house, could I have my applets save to my computer and read from my computer without having to learn JDBC and a DATABASE language. In other words could i just have my applet save and read text files from and to my server?
    I'm trying to set up a sight for my 5th grade class where parents can log into. Thanks for your time.
    Oh yeah, which is easier, learning how to set up a server or learning JDBC and a DATABASE language?
    If you have any other good idease please tell me them
    Thank you, Bryan

    Short answer: This isn't gonna work
    Long answer: For this to work, the first thing you're going to need is a static IP address and a DNS name registered -actually you don't necessarily need #2 but you're probably gonna want it and it's by far the easier of the steps.
    As far as I know to get a fixed IP address you've either gotta be directly attached to a larger network (ie university network) or get a leased line from an ISP.
    Once you've got that done come back to us.

  • DMS - file name and extension

    Hi everybody,
    I will appreciate if somebody could tell me how to read the file name and extension of already uploaded to DMS document (a function module will be best but name of db table is ok too). Is this information stored in SAP DB at all?
    Thanks
    Ogniana

    Check
    http://help.sap.com/saphelp_erp2004/helpdata/en/c6/893d55449311d1893e0000e8323c4f/content.htm
    Regards,
    Santosh

Maybe you are looking for

  • Memory speed 5900 XT

    Why I can't overclock the memory clock of my GFX 5900XT at more than 740Mhz... When the card memory is set at more than 740Mhz some triangles appear in the screen while 3Dmark 03 or some games are running. What i need.... a better power supply or som

  • I updated an iphone 3g and it does not want to restore after the backup.

    i have an old iphone 3g and there was an update available from my itunes. i updated and it went through the whole process, but when it started to restore and update i get a message saying that device was unable to restore unknown error (1015) i have

  • Thunderbolt ports bad?

    So, I thought I had an external drive problem.  My drive wouldn't work on either of my Thunderbolt ports on my 2011 Imac.  Then I connected the same thunderbolt drive and adapter to my Mac Air, and it worked. It's a 2011 Imac, Intel core i7, lots of

  • I'm unable to move or resize an image within a layer

    If I copy and paste an image into a new layer then I'm unable to drag and drop it, nor resize it. When I paste it then it gets pasted into the middle of the layer, if I select it and try and move it around it 90%  snaps back to the center.  Snap-to g

  • Macbook retina has no CD drive - how to install Windows??

    I have the new Macbook 15" retina and I'm trying to install Windows 7 via Bootcamp, but I just realized there is no CD/DVD drive on this model to insert the Windows disc. How to I install Windows and the drivers???