How do I find characters in a file?

Hi people who knows (a lot) more about Java than I do... :)
I have an array (intChars) containing integers written from a text file.
Now I would like to create a new array with all the positions in intChars where the character '{' happens to be.
I've tried something like this, but that doesn't seem to work. :(
            int posTuborgBegin = Arrays.binarySearch(intChars, (int)'{' ); What is a better way to find all the positions where a given character is in a file?
Please, don't give me an answer that a newbie can't understand. Thanks.
Regards,
Stefan

Maybe something like that, yes. But I don't
understand it fully.
I might need to take a brake...Have a look at this demo:
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Main {
    public static void main(String[] args) throws IOException {
        System.out.println(charIndexes("Main.java", '{'));
    static List<Integer> charIndexes(String fileName, char ch) throws IOException {
        int offSet = 0;
        List<Integer> positions = new ArrayList<Integer>();
        Scanner scan = new Scanner(new File(fileName));
        while(scan.hasNextLine()) {
            String line = scan.nextLine();
            for(int i = 0; i < line.length(); i++) {
                if(line.charAt(i) == ch) {
                    positions.add(offSet+i);
            offSet += line.length();
        scan.close();
        return positions;
}As you can see it uses a dynamic list (an ArrayList) to store the indexes of the occurrences of a specific character.
http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html
Edit:
Note that when you are reading your textfile as bytes you will receive different indexes since the EOL bytes will also get counted.

Similar Messages

  • How do I find out what program / file is using 100 GB of space on my Hard drive?  Once I find the problem  how do I delete the specific files to increase GB of space?

    How do I find out what program / file is using 100 GB of space on my Hard drive?  Once I find the problem  how do I delete the specific files to increase GB of space?

    Use OmniDiskSweeper
    Once you find file, it can be deleted from within OmniDiskSweeper
    Allan

  • How to make Finder NOT to show files from a specific folder in "All My Files"?

    Hello!
    Can someone please advice how to make finder NOT to show files from a specific folder in "All My Files"? See the attach - I recently installed Civilization 5 from Steam and now I have a lot of unneeded files (*.log and *.ini) shown in  All My Files colder in Finder.
    I don't want to see them. Any advise?

    Using "All my Files" was very handy before all this rubbish popped up. =(

  • How can i find total no of files in a directory ..using fileconnection

    how can i find total no of files in a directory.
    currently iam using
    Enumeration enum = fileconn.list(); and by iterating iam getting count.
    but the application is getting stuckup when the number of files in the directory is large.
    Is there any alternative. please help.
    thanks in advance.

    HI,
    this is a simple example with a cursor over user_tables view:
    set serveroutput on
    DECLARE
       CURSOR c_test IS
          SELECT table_name FROM user_tables;
       type t_reg is table of varchar2(30);
       l_reg t_reg;
    BEGIN
       OPEN c_test;
       fetch c_test bulk collect into l_reg;
       dbms_output.put_line(c_test%ROWCOUNT);
    END;
    /Output:
    SQL>
    SQL> set serveroutput on
    SQL> DECLARE
      2     CURSOR c_test IS
      3        SELECT table_name FROM user_tables;
      4     type t_reg is table of varchar2(30);
      5     l_reg t_reg;
      6  BEGIN
      7     OPEN c_test;
      8 
      9     fetch c_test bulk collect into l_reg;
    10 
    11     dbms_output.put_line(c_test%ROWCOUNT);
    12  END;
    13  /
    42
    PL/SQL procedure successfully completed
    SQL> Regards,
    Edited by: Walter Fernández on Nov 29, 2008 8:59 AM - Adding output...

  • How can I find .plist and .kext files?

    How can I find .plist and .kext files which are corrupt and need to be deleted before restarting and reloading applications)? Where are they hidden? How do I make them visible?
    /hezet

    Thank you Eric and Lanny for your answers!
    I was confused as the files could neither be found by Spotlight nor by the search field in the upper right corner of the Finder windows (why??), but I have located them now. The files were:
    AppleUSBEthernetHost.kext  The name appeared in i a warning window now and then.
    The .plist files were reported red (failed) by EtreCheck:
    com.apple.CSConfigDotMacCert-***@me.com-SharedServices.Agent.plist
    com.adobe.SwitchBoard.
    com.apple.netauth.sysagent.plist
    I have deleted all four files and restarted the computer. Now there are no items in red in EtreCheck, but none of the deleted files has been replaced after restart.
    So far the computer seems to work well. What action do you consider appropriate now?
    /hezet

  • Error message:    "There is no default application specified to open this document."  How do I find app. to open file??

    I am trying to NETGEAR software for a Wireless USB adapter.  When I put cd in and click autorun.exe file it says "There is no default application specified to open this document."  How do I find app. to open file??

    Or if you get stuck, post back with details of the Netgear device you are attempting to use.
    I'm sure that we can get it to work, but be prepared that it just MAY have to go back, if for example it requires Mac OS X 10.4 or later - I found a lot of networking USB dongles seem to require OS X 10.4.11 or later. But Netgear are one of the better device manufacturers, so I'm hopeful it'll work just fine.

  • How do i find the start up file information when booting OSX

    How can I find out what programs/files are started when I boot up my iMac?  Running latest OSX on i7 iMac

    Hello Klaus1
    thank you for your quick response.  My System Preferences pane does not show an Account section.  Any suggestions how I can get this to show?
    Thank you

  • How do I find the aperture image files so that I can attach them to an email

    How do I find the aperture image files? I know that you can email images from aperture. But how would I attach an image using Mail?

    if you mean to go into the Aperture library in order to get image files to print with Canon's software it's not really possible. The best you would be able to do would be to get the master image and if you're shooting RAW that will be the RAW file. In any case no adjustments you made to the image in Aperture would be available, versions don't exist as files until you export them.
    If you want to print with the Canon software you would export the image from Aperture and then print that image file.
    If I've misunderstood your question post back,
    regards

  • How do I find my original photo files in Iphoto?

    Well...Thanks Apple for censoring and deleting my previous discussion which DID contain useful and constructive information for many people who are trying to track down their photos in Iphoto.  I didn't realize how strongly censored this forum is.  I guess I shouldn't rant about it, or this will also get deleted.
    Once again, if anyone is trying to find their original picture files, open a Finder window > Places / your user name / Pictures / Iphoto Library ( Left click and select "Show Package Contents" / Originals.
    Also: as an Apple Forum user tip:  Don't be too critical of the Apple products or your post will be deleted.
    Thanks again LarryHN and Terence D for the help.

    Don't use iPhoto.
    iPhoto is a Photo Manager. It's designed to work like, say the AddressBook on your computer. Think of it this way:
    Add all your addresses to the Addressbook. Edit them, group and organise them as you will.
    If you need to access an address then simply use the tools built-in to every app in your Mac to do so - like the email or mail merge features and so on.
    *some where on the HD is all that information, but you wouldn't try and find that file, would you? You'd access the data via the Address Book application or the various hooks written into the Applications that integrate with it.
    Now, repeat swapping out the word 'address' for the word 'Photos'
    Add all your Photos to the iPhoto. Edit them, group and organise them as you will.
    If you need to access an Photo then simply use the tools built-in to every app in your Mac to do so - like the Media browser. These are detailed here:
    For help accessing your photos in iPhoto see this user tip:
    https://discussions.apple.com/docs/DOC-4491
    This User Tip
    https://discussions.apple.com/docs/DOC-4921
    has details of the options in the Export dialogue.
    What you are trying to teach the kids is a file based system. iPhoto is a data based system. If you don't want to teach the kids how to use a data based system then don't use iPhoto.

  • How do i find and download jar files?

    I have some old code and it uses import com.sun.java_cup.internal.parser
    When compiling gives error on this.
    Googleing this shows that its part of the rt.jar file. rt.jar is in the jre/lib folder. That is part of my classpath but still wont compile how do i find what an import belongs to and where can i download these jar files..
    Java really is not a friendly language to me.

    You don't need to download the rt.jar or do anything with it since it's an integral part of the JRE. If a class isn't there, then because you have too old a JRE/JDK and it's not there yet, or because it was never part of the public API and is gone now.
    When I google, I only find references to Java 6. So you probably need that, which means the sources can't be sooo old.

  • How can I find and delete duplicate files in Mt Lion?

    As a competent, but self-trained mac user for 30 years, I'm totally baffled by the sudden appearance of multiple duplicate documents and .jpgs in my imac files. How can I find and delete them?

    Duplicate Annihalitor - http://brattoo.com/propaganda/ - or Decloner - http://www.pixelespressoapps.com/decloner/
    LN

  • How can I find who deleted my files?

    Hello all.
    In my local network, A user see my share partitions and files then removed them, How can I find who did it?
    THanks.

    This question is duplicated (and answered) in:
    how can track who deleted file/folder from Windows Server 2008
    regards

  • How do I find the 'invisible' pdf file of the iphoto book?

    Hi!
    Under Panther, there was a technique for finding the pdf file that iPhoto created of the book that was sent to be printed. Since I last tried this technique, I upgraded both machine and system. Now the technique doesn't work. At least I can't find the right pdf file, anywhere.
    Has Apple changed how it creates the iphoto books? Is there a new way of naming the resulting pdf files? I'd like to check the file before ordering the book.
    Thanks!

    Try this way:
    How to Find the iPhoto Generated PDF File:
    1 - Start the ordering process and stop after the book has been assembled.
    2 - Since Spotlight cannot find and display invisible files it is difficult to locate the iPhoto generated pdf file. I use the application Kilometre, which does show invisible files, to locate and copy the PDF file to the desktop. You can also use a 3rd party application like Cocktail or TinkerTool to make all invisible file visible for this purpose but don't forget to make them invisible again after you're done.
    3 - The file will be located in your HD/private/var/tmp/folders.501/TemporaryItems/iPhoto folder. You can then Option-drag it to the desktop to get a copy of it.
    4 - Preview the PDF file and then, if satisfactory, you can continue with the ordering process.
    Hope this has been of some help. Good luck.
    O.T.

  • How do I find and locate duplicate files?

    What is the process to find and remove duplicate files. The tab is grayed out.   I am using version 13 and have over 1000 files and many of them are duplicates

    In unix you can use a combination of ls and diff.
    Unfortunately Apple is notorious for creating crippleware, so they have only provided this function in iPhoto and maybe iTunes.  There is no easy Finder solution, such as would make sense as part of Smart Folders!
    Stupid Apple 

  • My hard drive is full, i'm being told i have 284.03 GB of other.  How can I find out what these files are so i can delete them?

    My Mac is telling me that my hard drive is almost full, i have used 7.65 GB for Audio. 16.58 GB for Movies, 9.89 GB for photos, 788.6 MB for Apps and 284.03 GB for Other.  how can i find out what "other" is so I can delete it?  I hope someone can help me.

    If OS X is reporting you need to remove some items you obviously have a more severe issue.
    To fix your issue is likely too complicated and lengthy to go into all of it here as it sounds like a OS X issue, it will require the services of person very familiar and experienced with Mac's to first recover your data and then restore OS X back to a functional state which may or may not require new hardware/software installed.
    If your under warranty or AppleCare, take it in for service.
    You can also hire the services of a local Mac computer support technician experienced in these matters.
    Have them look at your Wifi, RAM amount, extra storage and computer backup proceedures in the process.
    Good Luck.

Maybe you are looking for

  • Key commands in Logic 8

    Can anyone confirm this: I have always used the key command "ctrlshift1" to attach "staccatto" to a note in score. If I now use this key command now, I only get screenset 1, no matter what I do. Could this be related to the scandinavian localization?

  • Can't update most CC apps to 2014 versions with company license

    Hi, my company has a CC account but I'm not in charge of it so I don't know the exact type. But it was a one-time setup from an individual installation file (no installation from the creative cloud app) on our office Macs. I don't remember having to

  • Application specific key-value pairs in jndi.properties

    Hello, Can I specify my application specific key-value pair in jndi.properties? I tried something like this java.naming.factory.initial=.jndi.WLInitialContextFactory java.naming.provider.url=t3://localhost:7001 myVar=myVal When i tried looking up "my

  • How to uninstall a DMG application

    My question is just what it says. How do you uninstall a DMG application? Please don't say "Just drag it to the trash" because that's not uninstallation. I installed Adobe Reader and found it was slower than Preview, so I was looking for a way to uni

  • Slideshow with border

    Hello, i am using iphoto and created a slideshow (with iphoto6, macmini, cinema display 23"). The slideshow works fine but there is a border about 1-2inches on each side around every picture. the resolution of the pictures is high enough for the scre