Reading in a certain number of characters from a file.

Hi guys,
I need some pointers on how to read in a specified number of characters from a text file.For example,how would I read in the first 100 characters to an array from a text file with an unspecfied number of characters (more than 100 rather than less!).
At present I am getting code errors being thrown due to reading in beyond the array size ie
java.lang.ArrayIndexOutOfBoundsException: 100.

post more code , this exception tells me nothing
without seeing what you are actually doing.
public String getText (String file)//textfile to be analyzed will be inputted as argument 150407 0356
   //15042007 0612 Check notes on overloaded getText method below.
       int temp;
       inputFile = file;
       int i=0;
            try
                BufferedReader bGetFile = new BufferedReader (new FileReader(inputFile));
                while ((temp=bGetFile.read())!=-1)
                    textFromFile[i] = (char)temp;
                    i++;
                /*for (int j=0;j<MAX;j++)
                    System.out.print(textFromFile[j]);//25042007 0208.For Testing purposes
                inputText=new String(textFromFile).trim();
                bGetFile.close();
            catch (IOException e)
                System.out.println (" ");
                System.out.println ("Sorry.An error occurred while trying to read from the input file.Unable to proceed!");
            System.out.println ("Processing the input text file "); //25042007 2318 being used for debugging purposes.          
            return inputText;
    }If the file being read is greater than MAX characters it will throw the exception mentioned.What I would like to do is read in MAX characters and discard the rest.

Similar Messages

  • Return selected number of characters from a string

    How do you select a certain number of charaters from a string?
    For example:
    I have a string that contains 51-108
    I want to separate the string into two strings one containing 51 and another one containing 108.

    A StringTokenizer will do it.
    StringTokenizer strtok = new StringTokenizer(yourString, "-");

  • Rounding After a Certain Number of Characters

    Hi,
    I'm looking for a way to round a number off after a certain number of characters. I'm not looking to round a number off after, say, the third or fourth decimal place, but after the third or fourth number. For example, If I round off after 3 characters, then:
    19235.6578 goes to 19200
    1.95723 goes to 1.96
    How would I go about doing this? Any help is much appreciated.
    Thanks,
    JOD8FY

    Thanks for your reply. What I'm really trying to do is round off an answer to the correct number of significant figures. According to the rules for multiplying significant figures, the answer will have the same number of sig figs as the number in the operation with the least number of sig figs. To do this, what I thought I would do is find the length() of the least precise number in the operation and then round off the answer after that many characters. So, if the least precise number has four sig figs, the answer will get rounded off after the fourth number. Hope this makes what I want to do a little clearer; sorry for being vague.
    JOD8FY

  • Does LabView program behave differentl​y under Traditiona​l Chinese version from regular English version. The program reads in numbers and characters from input files.

    Does LabView program behave differently under Traditional Chinese version from regular English version. The program reads in numbers and characters from input files.

    Hope this helps,
    Ankita

  • Re number of characters in a file name with leopard.. 10.5.3

    re number of characters in a file name with leopard.. 10.5.3
    Is there a limit? in a file or directory name?

    hfs+ == hfs extended, the default filesystem on a current mac...
    http://en.wikipedia.org/wiki/HFS_Plus

  • Removing number of characters from end of string

    Hi all....
    Dooza very kindly helped me with trimming a string in an
    earlier post, but
    now i want to remove the last four characters from a string.
    I really should know how to do this and will have to do some
    bedtime reading
    :-|
    But, for now, could someone help!
    Thanks
    Andy

    Ah Dooza - Thank You.
    To the rescue again :-D
    You're helping me to see the logic...
    Thanks Again
    Andy
    "Dooza" <[email protected]> wrote in message
    news:gbafel$ra3$[email protected]..
    > Andy wrote:
    >> Hi all....
    >> Dooza very kindly helped me with trimming a string
    in an earlier post,
    >> but now i want to remove the last four characters
    from a string.
    >> I really should know how to do this and will have to
    do some bedtime
    >> reading :-|
    >>
    >> But, for now, could someone help!
    >
    > Hi Andy,
    > Try something like this:
    > <%
    > myStr = "this is my really long string"
    > Response.Write(LEFT(myStr,LEN(myStr) -4))
    > %>
    >
    > Dooza

  • Read last characters from a file

    Hey All:
    i'm a novice when it comes to powershell- but this is what i'm trying to do.
    I have the following command-
    gwmi-classwin32_computersystem|selectName|out-filec:\computername.txt
    I want to then read the last three characters of the computername from the file. If there is a 'cleaner' approach
    please enlighten me.
    Thanks for all the help
    -Matlock

    Hi,
    Here's a method you can use:
    $name = (Get-WmiObject Win32_ComputerSystem).Name
    $shortName = $name.SubString($name.Length - 3)
    $shortName
    EDIT: Show on the draw, see Tommy's response above.
    Don't retire TechNet! -
    (Don't give up yet - 12,700+ strong and growing)

  • Reading Japanese Characters from Properties File

    I am running on Windows 2000 (English). Can any one suggest on how to read Japanese Characters from a ".properties" file.
    TIA

    look at ResourceBundle and unicode encoding,
    Jim

  • How can I limit running headers to a certain number of characters?

    I have a client that has a few very long headings in their book. The headings can't be re-written. The immediate problem is that I have running headers in this book, so when Frame is using one of these long headings for the running header, the running header is garbled. The text runs all the way to the end of the line, then it starts over at the beginning of the line over the words that are already there.
    Is there a method to limit the number of characters in a running header (or does someone know of another tactic) to force the running headers to display suitably?
    I'm using Frame 9 on Windows 8. (It also occurs on Windows 7 with Frame 9.)
    Thanks in advance for your help!
    Karen

    If the MasterPage frame that contains the RHF is only one row high, and suitably short, I would expect lone text string to get clipped at the frame edge. Problem is, that might be in the middle of a character.
    I'd be tempted to use a variation on the RHF trick described lately at:
    http://forums.adobe.com/message/5730734#5730734
    where each Heading1 has an anchored frame normally visible only to the author, containing the actual Heading1.RHF text picked for use in the header.
    For most instances, each Heading1.RHF could just be an Xref to the full Heading1.
    For the troublesome long Heading1's, the Heading1.RHF text would be hand-typed and shortened suitably.
    > The headings can't be re-written.
    In this hack, they aren't.
    > I have a client ...
    That's always an easy problem to fix .
    If the anchored frames become an issue, you can also use the Marker trick described by Arnis in that same referenced thread. Markers take up no visible space, but might be less obvious for future document stewards to puzzle out. That person might be you .

  • How to get total number of pages from .doc file without using Office interop?

    Hi,
    Kindly help me in getting the total number of pages from a .doc file not .docx file using C#. I know how to get by using Office interop but I do not want to use Office interop.
    So, without office automation in C# let me know how to get the total number of pages from a .doc file.
    Regards,
    Ashok

    Hi Ashok,
    >> I know how to get by using Office interop but I do not want to use Office interop
    Could you tell us why you don't want to use Office interop?
    As far as I know, this is the easiest way to achieve.Hmmm,this is my answer
    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.pagenumbers.startingnumber(v=office.14).aspx
    Best regards,
    Kristin
    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.

  • Maximum number of characters in displacement file

    Is there a maximum number of characters that can be in the name of a saved displacement file? When I save a displacement file with 12 characters or less, the Filter>Distort>Displace works fine; when I save the same file with 13 characters, nothing happens when I try to apply the filter. Obviously, the solution is to save files with 12 or fewer characters. I just wondered if this is a known limitattion. Thanks.

    Yes, the displacement files are in a "buried" folder, but they are in the same folder. One character did make a difference: displacement.psd worked, displacement1.psd didn't. I made a copy of displacement1.psd on the desktop and it did work so your idea that path length has importance is valid. Maybe it is the entire name of the file, path included, that is the determining factor. If so, it appears that the total number is somewhere around 122 characters. If there is a definitive answer to this question, please add it to this discussion. Otherwise, this question is answered. Another quirky Photoshop "Two-o'clock-in-the-morning-why-isn't-this-working" problem is resolved. Thanks!

  • Unable to pick unicode characters from input file using "outside in"

    Hi,
    I am using your product "Outside in" to read unicode text from input
    source file. For reading text I am using TReadFirst and TReadNext even
    though "It is not picking unicode characters from input source file
    and also it is giving zunk character to the buffer". How can I
    retrieve unicode character from input source using "outside in"
    product. Your help makes me learn more stuff.
    Regards,
    Naresh.D

    I am trying to use CAReadFirst and CAReadNext to read unicode characters. Even it is not picking, I think is there any flags we need to set. can any one help to this.

  • How do you read a large ( 100Mb) 3-D matrix from a file and make sure that you keep only one copy of it within the LV program for future use?

    I have to deal with large 3-D, I16 matrices that are stored in files. This data represents the density of an object at a sample point in 3-D space. I need to be able to display a 2-D section through the cube in an Intensity Chart. Since I want to update images in the intensity chart in real time to show different sections on demand I cannot adopt the approach of reading a section from the file when required - the I/O time assocaited with the disk read is way to long.
    The solution, is to keep EXACTLY one copy of the entire data set in memory at all times and then just get the required section on demand.
    This changes the disk I/O time to a memory access time, which is fast enough for my puposes.
    Here is the problem. Since the matrices are so large, I want to be very sure that I only keep one in copy of the data in memory. After a couple of weeks discussioin with Tech Support, and the development of several sample programs, they have agreed that it is not possible to do it with less than two copies of the data in memory.
    This additional memory requirement is a real problem for me and I am hoping someone is ingenious enough to come up with a way of doing it with only one.
    I can send a sample program illustrating the problem if necessary.
    Many thanks.

    Jean Pierre,
    Thanks for your reply - most kind of you to take the time. But.....
    This is exactly what I thought, and is similar in concept to the way I wrote my code. But it doesn't work. I modified you llb slightly by setting the variables to be I16's and setting the default array size to 54,000,000 and the default action to be initialize. ( I'll enclose a copy of my modified llb for you.)
    Here's what happened. I start the windows task manager, loaded LV and the program and looked at the memory shown in the task manager. It shows about 28Mb before I start to run the program. I then single step through the program. When it gets to the output of the Initial Array the memory usage jumps to about 134Mb, indicating the creation of the first copy of the array. As you continue single stepping it jumps to 239Mb as you leave the Case loop and head for the Shift Register. This memory does not drop down again.
    After talking with Platinum Tech Support, they agree and tell me that they cannot see a way to have just one copy of the array. That's why I posted it on the message board to see if there was anyone out there who had come up with an ingenious solution. It seems to be a serious limitation to labview.
    Let me know what you think.
    Thanks once again.
    Attachments:
    HugeArrayMod.llb ‏92 KB

  • STARTED IT, BUT STILL NEED HELP -- INPUTTTING CHARACTERS FROM LOADED FILE INTO TABLE, SELECTING STRINGS FROM TABLE AND PLACING IN NEW TABLE, SAVING NEW TABLE TO SPREADSHEET FILE

    I AM TRYING TO IMPORT CHARACTERS FROM A TAB DELIMITED FILE INTO A TABLE ON LABVIEW.  ONCE THE DATA IS IN THE TABLE I WANT TO BE ABLE TO SELECT INDIVIDUAL STRINGS FROM THE TABLE AND PLACE IT IN A NEW TABLE.  WHEN I CLICK ON A STRING I WOULD LIKE THE SELECTED STRING TO SHOW IN A TEXT BOX LABELED 'SELECTED STEP'  AFTER ALL THE SELECTED STRINGS IS IN THE TABLE I WOULD LIKE TO SAVE THE NEW TABLE AS ANOTHER SPREADSHEET -- TAB DELIMITED -- FILE, MAKING IT ACCESSIBLE TO OPEN.  HERE IS WHAT I HAVE SO FAR.  I CAN INPUT DATA INTO THE TABLE, BUT I CAN ONLY TRANSFER ONE STRING INTO THE TABLE I WOULD LIKE TO BE TO INPUT MULTIPLE STRINGS.    ALSO WHENEVER I TRY SAVING THE FILE, IT ALWAYS SAVES A UNKNOWN FILE, HOW CAN I GET IT TO SAVE AS A SPREADSHEET FILE.  THANKING ALL OF YOU IN ADVANCE FOR YOUR HELP!!!!!!
    Attachments:
    Selector.zip ‏30 KB

    Pondered,
       The question you are asking is the same one that you asked in: http://forums.ni.com/ni/board/message?board.id=170&message.id=132508#M132508, to which I supplied a revised version of the original vi you used (which was modified from the original one I supplied to an earlier thread). A couple of questions: 1) What does my latest not do that is in your question, 2) Why are you starting yet another thread about the same problem?  We are here trying to help, it makes it a lot easier if you keep the same problem in the same thread, it reduces duplication of effort from those that might not have been following the previous thread(s).  Those of us that don't have our "names in blue" are just doing this "for fun" (the blue names are NI employees, who may still be doing it "for fun"), and it makes it more fun if it doesn't seem (correctly or not) that our attempts are ignored.  If an answer doesn't help, or seems incomplete, post a little more detail to the same thread so that the original respondent, or someone new, can provide more information, or understand your problem better.
    P.M.
    Message Edited by LV_Pro on 07-20-2005 01:20 PM
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

  • Mapping question: How to only pass on a certain number of characters?

    I'm mapping a phone number from the idoc to the XML file.
    I only want to send the first 12 characters of a phone number.
    For example, if the phone comes in as, "123-456-7890 Ext 44", I only want to send "123-456-7890".
    I thought I could use the substring function(0 to 12), but I get an error if the phone is not exacly 12 characters long.
    I need to be able to process the value of the phone number if it's:
    Blank
    Has text like "no phone".
    1234567890
    123-456-7890
    Is there a std function to do this, or would I need a custom java udf?
    Thanks,
    jeff

    Jeff,
    you can write a UDF with the following conditions.
    I am not so good at Java programming. Hence I am giving you the logic try to draft a UDF using Java.
    for(i=0; i<=11; i++) //worst case you are interested in first 12 values in the incoming payload incl "-"
    1. If the read character is one of the alphabets or "" do not pass //to take care of blank or no phone or NA
    2. If the read character is - do not pass.
    3. If the read value is digit, pass it
    if the concatenated string == 10 then pass it to target field.
    if concatenated string =="", do not pass or take corresponding action.
    this ways, the "NA" or "no Phone" or "" will be filtered out
    Hope its useful
    Venkat.

Maybe you are looking for

  • IWeb Image Size

    Hello Apple Friends, What's the easiest way to get iWeb images down to a reasonable size? The PNGs are just too big as they're created automatically. Is there a setting I can adjust somewhere? I hope I don't have to go in and manually shrink each ima

  • Error code -39 "How do I fix this please"

    I purchased 3 films from Itunes, they started to download and then stopped, when I tried to resume download they will not download and I get an error code -39 asking me to check connection and try again. My connection is fine but I keep getting the s

  • Trouble loading Photoshop from special offer

            I just loaded Adobe Creative Cloud at the $9.99 per month special rate. However I am unable to get the Photoshop program running. I don't see a Photoshop screen going--just a download screen. What do I do? Help!!!!!

  • Duplex Printing Question

    Hi All, I'm printing ABAP list in Duplex mode but for some reason every other report will not print on the back of the first page? My device type is HPLJ4000 R4.5A+Only and the access method is C: Direct Operating System call. Any help would be appre

  • Vbscript comparing registry key software versions - problem

    Function GetNACKey() Dim oReg, sPath, aKeys, sName, sKey, sVersion Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") sPath = "SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" oReg.EnumKey HK