Reordering within a text file

HI all,
I have a text file in the following format
Part 1     Part 2
p2_f1     p2_f2     p2_f3     p2_f4     p2_f5     p2_f6          
p1_f1     p1_f2     p1_f3     p1_f4     p1_f5     p1_f6
the above file is tab delimited
I would like to reorder the file in such a way that
when first word of the first line is " Part 1" then the second line should be
p1_f1     p1_f2     p1_f3     p1_f4     p1_f5     p1_f6
if the second word in the first line is " Part 2" then the third line should be
p2_f1     p2_f2     p2_f3     p2_f4     p2_f5     p2_f6
basically the lines after the first line in the text file should be sorted based on the words in the first line.
Any ideas on how I could proceed?
Thanks in advance.

Hello ,
I have changed the code to initialize the hashmap.
My code is
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Reorder {
    public static void main(String args[]) throws IOException {
        FileInputStream fstream = null;
        try {
            fstream = new FileInputStream("E:\\Documents\\reorder.txt");
//Variable Declarations
            String strLine;
            Map<String, String> entries = new HashMap<String, String>();
            ArrayList<String> partlist = new ArrayList<String>();
// Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            while ((strLine = br.readLine()) != null) {
// Intialize tokenizer
                String s = strLine;
                StringTokenizer tokenizer = new StringTokenizer(s, "\t");
                while (tokenizer.hasMoreTokens()) {
// add data to collection
                    partlist.add(tokenizer.nextToken());
// Sort The data
                    Collections.sort(partlist);
// Adding to hashmap
                    String key = strLine.substring(0, 2).replace("p", "Part ");
                    entries.put(key, strLine);
//                    System.out.println(partlist);
// Printing the hashmap
            System.out.println(entries);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Reorder.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                fstream.close();
            } catch (IOException ex) {
                Logger.getLogger(Reorder.class.getName()).log(Level.SEVERE, null, ex);
}But I have no clue as to how to add the read line part
String firstLine = readFirstLine();
String[] parts = split(line);and the write part
write(firstLine);
for(String part: parts){
   write(entries.get(part));
}my output now looks like this
{Pa=Part 1        Part 2, Part 1=p1_f1        p1_f2        p1_f3        p1_f4        p1_f5        p1_f6, Part 2=p2_f1        p2_f2        p2_f3        p2_f4        p2_f5        p2_f6}
Thanks in advance.
Edited by: Spry.chipper on Dec 13, 2009 10:53 AM

Similar Messages

  • Find words within a text file

    Hey all.
    I am playing around with the idea of finding a line of text within a text file, by using scanner and some next methods.
    The way I am trying to get it to work is that one enters a string and the program then finds all the lines of text containing that
    user-entered string and then prints them.
    The text file in question contains names of University papers and their room numbers, quantity of students etc.
    Example:
    IBUS212     EALT006     1am     72     AL     LI     
    BMSC241     MCLT102     2     pm     8     AL     COOREY     
    My problem annoyingly enough seems to be that I can't think how one could compare the string entered to the lines of text being
    scanned in the text file.
    My latest go involved what you see in the code, scanning the examdata.txt file for a user-entered course number, using course.next();
    by going with the example above it would be IBUS212. The task was to then to find all of the lines containing that number and print them out using
    println (what I have tried with id and line) as well as the rest of that line eg: EALT006     1am     72     AL     LI .
       public void printCourse()
        try
            String details, input, id, line;
            int count;
            Scanner user = new Scanner(System.in);
            System.out.println();
            System.out.println();
            System.out.println("Please enter your course ID: ");
            input = user.nextLine();
            Scanner course = new Scanner(new File("examdata.txt"));
            course.next();
            course.nextLine();
            id = course.next();
            line = course.nextLine();
            if(input.equals(id))
                System.out.println("Your course times are: "  + id + "and" + line);
            else
              System.out.println("Your course does not exist."); 
            catch(IOException e)
                System.out.print("File failure");
      }Any advice/help/troubleshooting would be greatly appreciated.
    Edited by: AUAN on Aug 13, 2009 9:43 AM
    Edited by: AUAN on Aug 13, 2009 9:44 AM
    Edited by: AUAN on Aug 13, 2009 9:49 AM

    You'll want [to loop while|http://java.sun.com/docs/books/tutorial/java/nutsandbolts/while.html] the course Scanner has a next line and then print the line if it contains the entered text.
    For useful methods you can check the Javadoc of String and Scanner (use your browser search on keywords like 'next' or 'contains' to find them).

  • How to search a String within a text file ?

    ************** text file ****************
    Good bye good
    bye good bye
    good bye
    good bye good
    bye good
    ************** Input and Output ****************
    Input: good bye
    Output:
    total strings Matched: 5
    whichlinesmatched: 2
    whichlinesmatched: 2
    whichlinesmatched: 3
    whichlinesmatched: 4
    whichlinesmatched: 5
    whichlinesmatched: 0
    whichlinesmatched: 0
    whichlinesmatched: 0
    whichlinesmatched: 0
    whichlinesmatched: 0
    ** but the desired output is 3, and only line 2, 3, 4 matched
    ** Could you please have further help about this? Thank you.
    ************** the codes****************
    import java.io.*;
    public class Tokenize{
    public static void main( String args[] ){
    int maxNumberOfLine = 1000; //the maximium number of line in data file for input
    String fileName = "test"; // file name for data input
    String stringForCount = "good bye"; // specified word for counting
    int totalStringMatched = 0; // number of word matched
    int[] whichLineMatched; // line number for each word matched
    whichLineMatched = new int[maxNumberOfLine];
    // Input string (stringForCount) has been stored in a string array, wordForCompare[]
    // For example: stringForCount = "good bye"
    int stringLength = 2;
    String wordForCompare [] = { "good" , "bye" };
    // wordForCompare[0] = good
    // wordForCompare[1] = bye
    int wordFromFile;
    StreamTokenizer sttkr;
    try{
    FileInputStream inFile = new FileInputStream(fileName); //specifying the file to be opened
    Reader rdr = new BufferedReader(new InputStreamReader(inFile)); //assigned a StreamTokenizer
    sttkr = new StreamTokenizer(rdr);
    sttkr.eolIsSignificant(false);
    System.out.println("Searching for word : " + stringForCount );
    while( (wordFromFile = sttkr.nextToken()) != StreamTokenizer.TT_EOF)
    System.out.println( "going looping through file, token is: " + sttkr.sval );
    if(sttkr.sval.equals(wordForCompare[0])){
    if (stringLength == 1) {
    totalStringMatched++;
    whichLineMatched[totalStringMatched-1]=sttkr.lineno();
    } else {
    for (int p=1; p < stringLength; p++) {
    wordFromFile = sttkr.nextToken();
    System.out.println( sttkr.sval );
    if (!(sttkr.sval.equals(wordForCompare[p])))
    break;
    else if (p==stringLength-1) {
    totalStringMatched++;
    whichLineMatched[totalStringMatched-1] = sttkr.lineno();
    } // end of else
    } // end of for-loop
    } // end of else
    System.out.println( " total strings Matched: " + totalStringMatched );
    } // end of if
    }//end of while for wordFromFile
    for( int i = 0; i < 10; i++)
    System.out.println( "whichlinesmatched: " + whichLineMatched<i> );
    } catch(Exception e) {} //end of try
    }

    A small change to roopa_sree's code, this code fails if there are multiple occurences of the search string in the same line. Make this small change to correct it,import java.io.File;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.util.StringTokenizer;
    public class WordCounter {
         public static void main(String args[]) throws Exception {
              if(args.length != 1) {
                   System.out.println("Invalid number of arguments!");
                   return;
              String sourcefile = args[0];
              String searchFor = "good bye";
              int searchLength=searchFor.length();
              String thisLine;
              try {
                   BufferedReader bout = new BufferedReader (new FileReader (sourcefile));
                   String ffline = null;
                   int lcnt = 0;
                   int searchCount = 0;
                   while ((ffline = bout.readLine()) != null) {
                        lcnt++;
                        for(int searchIndex=0;searchIndex<ffline.length();) {
                             int index=ffline.indexOf(searchFor,searchIndex);
                             if(index!=-1) {
                                  System.out.println("Line number " + lcnt);
                                  searchCount++;
                                  searchIndex+=index+searchLength;
                             } else {
                                  break;
                   System.out.println("SearchCount = "+searchCount);
              } catch(Exception e) {
                   System.out.println(e);
    }Sudha

  • Add date to new text file name and generic text in body

    Okay, I hope this is the right forum. To help manage and keep track of incoming assets/files and I created an Automator workflow with the following: "Get Selected Finder Items → Get Folder Contents → New Text File (w/Show this action when the workflow runs so I can give a unique name).
    This creates a text file with the folder contents listed in the body.
    I would like to know if I can do two things:
    1. Automatically add a date/time stamp to the Save as field so it will automatically have a unique file name?
    2. I also want to add text before the listed contents within the text file. (e.g.: Let's say the folder contents are Volumes/Mac HD/Generic_movie.mov. I want the final text to read:
    "The following file has been moved to the local volume at: Volumes/Mac HD/Generic_movie.mov"
    Is there a way to accomplish either one or both of these with Automator or AppleScripts?
    Thanks.

    I would like to know if I can do two things...
    This might address your first concern:
    *1) Get Selected Finder Items*
    *2) Get Folder Contents*
    *3) New Text File* -- select a destination folder and check *Show Action When Run*
    *4) Rename Finder Items:*
    Choose *Add Date or Time* from the popup
    Date/Time: select Created, Modified, or Current - Format: *Month Day Year*
    Where: *After name* - Separator: *Forward Slash*
    Separator: Space - check *Use Leading Zeros* (optional)
    *5) Rename Finder Items:*
    Choose *Add Text* from the popup
    Add: *" at"* -- put a leading space before "at" (without the quotes), and select *after name*.
    *6) Rename Finder Items:*
    Choose *Add Date or Time*
    Date/Time: Current - Format: *Hour Minute Second*
    Where: *After name* - Separator: Dash
    Separator: Space - check *Use Leading Zeros* (strongly recommended)
    +--- End of Workflow ---+
    Save the workflow as an application and use it as a droplet. Drop a desired folder onto the saved applet and enter a name when the dialog appears. The new text file, which will be found in the destination folder, should be appended with a date and time stamp, e.g., *"My Folder List 7/8/2010 at 23-54-09"*
    Tested using Mac OS 10.4.11 and Automator v. 1.0.5
    Good luck; hope this helps.

  • Create a text file output from within a procedure

    I can output to a file from within SQL+ using the spool command but how do I do this from within a procedure?
    I have got a table called ABC and want to output columns A and B to a new text file based on variables pased through when the procedure is run, the name of the text file should be generated from a sequence?
    Any info appreciated.
    Cheers
    Cliff

    Hi,
    U can use UTL_File Package, But the only constraint is it will write the file only on the server m/c and not on the client m/c.
    Regards
    Gaurav

  • How do i read a context of text file within Dynamic Page of portal ?

    Dear sir,
    I have a text file in client computer. I hope i can transfer the context words of this text file to oracle database. How do i coding this script in dynamic page of portal?
    Can Oaracle 9ias script read and draw the context of a document. Thank you ver much!
    Ghia Liu

    Great questions, Rik, and I understand how this might seem bizarre. Here's the story... these 2500 files were authored with a built-in authoring tool of our current knowledge management system. This KMS is about to be replaced with a new one and because the new KMS needs content within the <head> tag instead of where it was in the <body> tag and redefined as meta data, I repuposed the content in those files using Dreamweaver and regular expressions.  However, the one remaining <h3> and <p> content is in the middle of the newly tagged meta data and it must be moved from the <head> area and into the <body> area.
    Because these were authored in the built-in KMS authoring tool, there is no style sheet and no, we do not manage our content with a CMS.
    You are correct, if the <h3> and <p> were at the end of the data, I could simply move the </head> and <body> tags, but unfortunately that is not the case.  They are consistenly in the same place in all 2500 files, but in the middle of the data. Following is an example:
    <html>
    <head>
    <title>Title here</title>
    <meta name="XYZ" content="Something here...">
    <h3> Blah blah</h3> <p>More blah blah</p>
    <meta name="123" content="More somthing here">
    <meta name="456" content="More somthing here">
    </head>
    <body>
    </body>
    </html>
    Again, I can find the block using a regular expression <h3>(.*?)</p>, but dont know what to do after that.
    I've been told that perl or grep might do the needed task, but that requires outside resources and I have no budget for that.
    Any suggestions are greatly appreciated.
    thanks,
    Rick

  • I want to open a text file and display it within Lookout 5.0

    How do you read and display a text file within Lookout 5.0?

    Hi Kenneth,
    This should have been trivial, but isn't. Well, it isn't that difficult either. Here's the trick:
    Create a DataSocket Object. For the URL, type: file:c:\ni\lookout5\test.txt[text]
    Leave the Update mode as Automatic for now. Connect a Switch to the Connect member of the DataSocket object.
    On the panel, drag-and-drop the DataSocket.data.txt. Toggle the Switch and voila you have the text in Lookout! I have attached an example (detach the txt file to your C drive; or change the path in the DataSocket object).
    For the curious, DataSocket is a NI networking technology which supports ftp, http, file, and other protocols. See this
    >FAQ f
    or general info' on DataSockets.
    Hope this helps,
    Khalid
    Attachments:
    test.txt ‏1 KB
    readtext.lks ‏2 KB

  • Text file within jar file

    Can anybody tell me if it's possible to read and write to a text file stored within the .jar file package? I can maintain a constant file length if that enables me to read and write.
    cheers,
    Steve

    reading a text from, from a jar file..... if the jar is in your classpath you can call
    getClass().getResourceAsStream ( "/myServerConfig.properties" );Note the "/", which stops the file from being interpreted as a class name, see Class.getResourceAsStream()
    writing... nothing as easy as the reading solution above.
    You'd probably have to actually "update" the JAR file contents with a new version of the text file.
    regards,
    Owen

  • Static method to read text file within JAR.

    I've a small problem. I've got my JAR file stuff working great, so I thought I'd give a go to running it via WebStart. Through a little research, I've found that if you're distributing your application via WebStart, you need to pack up everything in a JAR file. This is no problem for the JDBC drivers, because its already in a JAR, so I should be able to distribute that fine.
    I've managed to digitally sign my application JAR and have a preliminary (i.e. untested) JNLP file set up.
    My problem is, my application gets its available data sources from an external text file. I've already written my own file I/O class which I use in my "commonfiles" package to read in a text file and return it as an array with each element holding a line from the text file. This class is basically just a bunch of static methods.
    So instead of rewriting this, I thought I'd just add a boolean flag to this method to state whether to load this file from the external file system or the JAR file. I've found out that to load a text file from within the JAR you have to use something like: -
    String str = (this.getClass().getResource("/myData.txt")).getFile();
    java.io.File fil = new java.io.File(str);
    java.io.FileReader fr = new java.io.FileReader (fil);
    java.io.BufferedReader bin = new java.io.BufferedReader (fr) ;The sticking point is that my method (ReturnFileAsArray()) is declared as static, because my own FileIO class is just a bunch of static methods to do file I/O stuff. Therefore, I can't use the above method because of the instance variable "this" (I assume).
    Is there any way I can load an included text file as above without having to declare my method as an instance method? I guess I could write a seperate class to do this for my commonfiles package, but I'd rather not if possible.
    Any ideas?

    Don't put a "flag" and code different ways to read files depending on whether it's in a JAR or not. Just use
    the getResource/getResourceAsStream API regardless. Hmmm.....so that will load it from either place depending on the situation? I keep getting a NullPointerException doing that, on this line: -
    String strFileName = (FileIO.class.getResource(fileName)).getFile();...although I've only tried it using the external local filesystem file (in the same directory) as I've not really finished setting up my WebStart stuff yet.
    Here is the method in question...
    public static String[] ReadFileAsArray(String dirName, String fileName, boolean bFromJAR) {
            String[] resultStringArray = null;
            StringBuffer strBuffer = null;
            StringTokenizer strTokenizer = null;
            FileReader fReader = null;
            BufferedReader bReader = null;
            int iElementCount = 0;
            if ((dirName.length() < 1) || (fileName.length() < 1)) {
                // Null parameters found. Failure.
                return null;
            } else {
                // Parameters correct, continue.
                try {
                    // Read the file contents and convert to String array.
                    //if (bFromJAR) {
                        // Open file from within JAR file.
                        String strFileName = (FileIO.class.getResource(fileName)).getFile();
                        File jarFile = new File(strFileName);
                        fReader = new FileReader(jarFile);
                    //} else {
                        // Open from local filesystem.
                    //    fReader = new FileReader(dirName + File.separator + fileName);
                    bReader = new BufferedReader(fReader);
                    strBuffer = new StringBuffer();
                    while (bReader.ready()) {
                        strBuffer.append(bReader.readLine() + "%%");
                    strTokenizer = new StringTokenizer(strBuffer.toString(), "%%");
                    resultStringArray = new String[strTokenizer.countTokens()];
                    while ((strTokenizer.hasMoreTokens()) && (iElementCount < resultStringArray.length)) {
                        resultStringArray[iElementCount++] = strTokenizer.nextToken();
                    bReader.close();
                    return resultStringArray;
                } catch (IOException e) {
                    return null;
        }I'm calling it using: -
    // Load the external file into a String array, one row for each element.
    String[] fileArray = FileIO.ReadFileAsArray(System.getProperty("user.dir"), "datasources.dat", true);Cheers on any info on this.

  • Is it possible to export all information (metadata, list of pictures within each album or project) about ALL pictures in Aperture to text files, in a single operation?

    I have downloaded a trial version of Aperture because I would like to switch from using Picasa and gimp to using Aperture.  I already know that I want to use Aperture, and that I cannot learn how in 30 days.  I want to use the 30 days to see if I can solve a different problem: bulk export of all information except edits and versions from Aperture.
    I want to avoid locking information (other than than the edits and version information that Aperture maintains) about my photos into any one piece of software.
    Picasa stores a copy of almost all its information in text filies (mostly XML or .ini format) that are scattered through its picture library.  These files can be scanned and found by use of Mac OS X tools that are availabe in Terminal (at the bash command line).  All of the information about albums, faces, etc can be exported by a single command (after wtiting the progams that the command will initiate.  I have not yest found any similar files in Aperture.
    Aperture supports the export of EXIF and IPTC metadata, but only for selected photos, and does not appear to support the export of other information at all.
    What I would like to do with a single operation, from either Aperture or Terminal, is to export the entire arrangement of phost ins albums and projects, lists of albums, projects and phots with all metadata (including added keywords) attached to each, and for referenced photos, the external file name.  I do not care if would be in one file or many different text files, because Mac OS X provides all the tools I would need to extract the information I would want from any number of text files.
    This would allow me to reconstruct all of the information about my photos (except for edits and versions) outside Aperture, and to use that info in a database outside Aperture.  I would then be able to use Aperture while still being able to do everything that I could do with Picasa.
    The most helpful form of an answer to this question might be a list of places to look in the Apple support and Apple developer documentation.  It is difficult to teach me anything complicated, but I am fairly good at figuring out things from documentation.

    The following script recursively lists the content of an Aperture library.  The output is simple, for demonstration puposes, but could be modified to XML.  If the XML were that of a PLIST, the Apple Property List viewer oculd be used to diaplsy the output.
    A simlar script produces all of the keywords and tags for all of the images in Aperture.
    The scripts run much faster in the shell than in the AppleScript Editor bcause the shwll produces no debugging or monitoring information.
    #!/usr/bin/env osascript
    (*    Demo: list the containment hierarchy in Aperture, starting from libraries.
        Runs from AppleScript Editor, or as a shell command
        References:
            Aperture 3 AppleScript Reference Manual,
                particularly the Containment Diagram in Appendix A
                from the link on "Aperture Resources" web page at http://images.apple.com/aperture/resources/
            Aperture AppleScript Dictionary, accessed from AppleScript Editor
        Ian E. Gorman
    global outputFile
    set outputFilePath to "/Users/ian/prj/sw/AppleScript/ApertureContainment.txt"
    global lineEnd
    set lineEnd to "
    global tabChar
    set tabChar to "    "
    on writeText(str)
        write str to outputFile
    end writeText
    # Open the file, guarantee closure after any error, and list the contents of Aperture libraries
    try
        set outputFile to open for access POSIX file outputFilePath with write permission
        set eof outputFile to 0 # truncate the file, if it already exists
        my listAll()
        close access outputFile
    on error errorMsg number errNum from offendingObj partial result resutList to expectedType
        try
            display alert "Operation failed, attempting to close output file" & lineEnd & "Error number " & errNum & ": " & errorMsg
            close access outputFile
            display alert "Operation failed, but output file has been closed"
        on error
            display alert "Operation failed, also failed to close output file"
        end try
    end try
    # top-level in Aperture
    on listAll()
        tell application "Aperture"
            repeat with eachLibrary in libraries
                my listLibrary(0, eachLibrary)
            end repeat
        end tell
    end listAll
    on listLibrary(level, thisLibrary)
        local newLevel
        set newLevel to 1 + (level as integer)
        tell application "Aperture"
            my writeText((newLevel as rich text) & tabChar & "library" & tabChar & (name of thisLibrary) & lineEnd)
            repeat with eachAlbum in albums of thisLibrary
                my listAlbum(newLevel, eachAlbum)
            end repeat
            repeat with eachFolder in folders of thisLibrary
                my listFolder(newLevel, eachFolder)
            end repeat
            repeat with eachProject in projects of thisLibrary
                my listProject(newLevel, eachProject)
            end repeat
            repeat with eachImageVersion in image versions of thisLibrary
                my listImageVersion(newLevel, eachImageVersion)
            end repeat
        end tell
    end listLibrary
    on listAlbum(level, thisAlbum)
        local newLevel
        set newLevel to 1 + (level as integer)
        tell application "Aperture"
            my writeText((newLevel as rich text) & tabChar & "album" & tabChar & (name of thisAlbum) & lineEnd)
            repeat with eachImageVersion in image versions of thisAlbum
                my listImageVersion(newLevel, eachImageVersion)
            end repeat
        end tell
    end listAlbum
    on listFolder(level, thisFolder)
        local newLevel
        set newLevel to 1 + (level as integer)
        tell application "Aperture"
            my writeText((newLevel as rich text) & tabChar & "folder" & tabChar & (name of thisFolder) & lineEnd)
            repeat with eachAlbum in albums of thisFolder
                my listAlbum(newLevel, eachAlbum)
            end repeat
            repeat with eachFolder in folders of thisFolder
                my listFolder(newLevel, eachFolder)
            end repeat
            repeat with eachProject in projects of thisFolder
                my listProject(newLevel, eachProject)
            end repeat
            repeat with eachImageVersion in image versions of thisFolder
                my listImageVersion(newLevel, eachImageVersion)
            end repeat
        end tell
    end listFolder
    on listProject(level, thisProject)
        local newLevel
        set newLevel to 1 + (level as integer)
        tell application "Aperture"
            my writeText((newLevel as rich text) & tabChar & "project" & tabChar & (name of thisProject) & lineEnd)
            repeat with eachAlbum in albums of thisProject
                my listAlbum(newLevel, eachAlbum)
            end repeat
            repeat with eachSubfolder in subfolders of thisProject
                my listSubfolder(newLevel, eachSubfolder)
            end repeat
            repeat with eachImageVersion in image versions of thisProject
                my listImageVersion(newLevel, eachImageVersion)
            end repeat
        end tell
    end listProject
    on listSubfolder(level, thisSubfolder)
        local newLevel
        set newLevel to 1 + (level as integer)
        tell application "Aperture"
            my writeText((newLevel as rich text) & tabChar & "subfolder" & tabChar & (name of thisSubfolder) & lineEnd)
            repeat with eachAlbum in albums of thisSubfolder
                my listAlbum(newLevel, eachAlbum)
            end repeat
            repeat with eachSubfolder in subfolders of thisSubfolder
                my listSubfolder(newLevel, eachSubfolder)
            end repeat
            repeat with eachImageVersion in image versions of thisSubfolder
                my listImageVersion(newLevel, eachImageVersion)
            end repeat
        end tell
    end listSubfolder
    on listImageVersion(level, thisImageVersion)
        local newLevel
        set newLevel to 1 + (level as integer)
        tell application "Aperture"
            my writeText((newLevel as rich text) & tabChar & "image version" & tabChar & (name of thisImageVersion) & lineEnd)
        end tell
    end listImageVersion

  • Reading a text-file from within a Jar-file...

    I've made a program, that reads from a text-file. And it works great. But when I try to put the program into a jarfile, I get a fileNotFoundException... I have the textfile both inside and outside the jarfile... with the same result.
    Does anyone know what I might be doing wrong?
    Thanx in advance!
    Martin

    Depends on the path you enter for the text file. If you simply put "filename.txt" then you should try to have the file in the same directory as the class which accesses the file.
    Cheers,
    H�vard

  • Jump within a BIG text file

    Hi,
    I have a text file with more than 3 million lines.
    How can I easily jump to a specific line without reading line by line.
    e.g. using the class RandomAccessFile to jump you need the number of bytes.
    But each line has diffrent numbers of characters, thats why I can't jump directly via "seek" method.
    thanks
    Aykut

    aykut_arslan wrote:
    @paul.miner
    can you write a little code, his suggestion of reading the file is not clear for meNo, that's for you to do. If you can at least write a good start, you can get help here, but I'm not going to write it for you.
    I will give you some pointers:
    1. Use RandomAccessFile.
    2. The position you seek() to in the file should be directly proportional to the position of the scrollbar (e.g., if scroll bar is at 42% of it's maximum, seek() to 42% of the file size).
    3. After seeking, read forward until you encounter a line break. Start displaying text from that position.
    EDIT: Or just go with indexing, which is far simpler. As BDLH suggested, background processing is a good option. You could also make it so that the scroll bar position is proportional to the number of lines read so far, not the size of the file.
    Edited by: paul.miner on Jan 16, 2008 2:29 PM

  • Replace a string within text file to another string

    hi everybody
    i wich to replace some word writed in text file to another word,,,,for example i want to replace all word when the word is "SOLARIS" to "solaris" .
    anyone have an idea to resolve this prob via command or script,plz respond me.
    thanks

    To elaborate on alan.pae's response:
    sed 's/SOLARIS/solaris/g' oldfilename > newfilename
    -systemstate

  • Saving to text file from GUI within linked list

    can anyone help me with saving to a text file from a GUI text area and text fields??
    then reading back into the labels and textfields from the text file??
    It's currently just saving in a linked list and creating a new item inside of it. but i have to now make a text file for each item, this is what i currently have
    i need to turn this into something that with save to text file with buffered reader or something, can anyone help???
    public void saveToFile()
            while(listIterator.hasNext())
                item = (Item)listIterator.next();
                saving.save(item);
        }//END SAVETOFILE
        public Object save(Item item)
            if (last == 1)
                itemList.set( listIterator.nextIndex() , item);
            else
                itemList.set(listIterator.previousIndex(), item);
            itemList.set(listIterator.previousIndex(), item);
            listIterator = itemList.listIterator(0);
            return itemList.getFirst();   
        }//END SAVE

    thank you sztyopek, i am still having trouble getting it to save to text file. I have to do it through a client and server so i have a protocol class. in the protocol class i have
    if (o instanceof String)
                        //System.out.println(o);
                        if (o.equals("next"))
                            newo = database.getNextItem();
                           // some how send newo
                        if (o.equals("prev"))
                            newo = database.getPrevItem();
                            //some how send newo
                        if (o.equals("save"))
                            database.saveToFile();
                        if (o.equals("exit"))
                            System.exit(1);
                    }//END IF STRING
             if (o instanceof Item)
               newo = database.save((Item)o);
            return newo;
        }When i save what i have entered in the textfields for each record it doesn't create a textfile. and it still getting retrieved from how i set it up before by going to the database.save((Item)o)...the last if statement above but i can't change that to the saveToFile method that u helped me with it says incompatible types or something.
    this is the method it is going to, i assume i have to get rid of this so i stop getting the information from the list and start getting it from the text file.
    public Object save(Item item)
            if (last == 1)
                itemList.set( listIterator.nextIndex() , item);
            else
                itemList.set(listIterator.previousIndex(), item);
            itemList.set(listIterator.previousIndex(), item);
            listIterator = itemList.listIterator(0);
            return itemList.getFirst();   
        }//END SAVEif this makes any sense can u give me a hand.
    As to rob the guy bagging me........i am doing a bachelor of networking and they make us do java for the first year. this is my last semester and last assignment. it is also the last thing i have to do for the assignment. I am not good at java so that is why i am asking for some help i just want to pass this semester then i am never doing it again.
    thanks.

  • Print Text File in NW 3.12?

    I have to admit some ignorance regarding NetWare printing, so my
    apologies in advance...
    I work for a document management company, and am trying to find a
    solution for a customer running a fairly archaic, DOS 6.22-based
    application that utilizes a NetWare 3.12 server for file and print
    services. My need is to retrieve print output from their application,
    in the form of a text file, and then reprocess it for automated faxing
    through a fax server device.
    My problem is this: their application seems to print directly to a
    printer by defining what it calls a "network port" (which seems to map
    to a spooler, 0 through 5) or LPT1, and by referencing a printer
    definition. As far as I can tell, the files that are deposited in the
    print queue are byte streams, i.e., they're not human-readable (they
    have extra characters that I'm assuming are control characters). They
    therefore aren't usable by my print distribution software.
    I've tried using CAPTURE to send to a text file, but the application
    seems to conflict with the command. If I set CAPTURE, then start the
    application and send a job to LPT1, the application returns an error
    that the printer is unavailable. Upon exiting the application the port
    is no longer being captured (although I've tried all of the options I
    can think of to keep it so). Oddly enough, the application does
    successfully print a text file to LPT2 (for a barcode printer), which
    is CAPTUREd via a command in the system autoexec.bat. This is done a
    different part of the application.
    If anyone can help me figure out a way to generate a text file in this
    environment, or to work with the print file that's currently being sent
    to the queue (e.g, can it be translated somehow to a simple text file?),
    that would be much, much appreciated. This customer is in a tight spot,
    with an unsupported application that they can't presently afford to
    upgrade. My solution would save them enough money over time to replace
    the system.
    Again, thanks in advance for any help!
    wynand32

    If the Dos app has no print drivers included, then indeed it is relying
    on NW and PRINTDEF/PRINTCON to do the formatting stuff. That must have
    already been set up for it to be successfully printing now, it's just a
    matter of adding a definition that doesn't do anything to the print text.
    >In fact, given my ignorance of the NetWare environment, I'm not sure
    how the term "driver" even applies, unless it would refer to the
    printer definition.
    I was referring to a driver within the Dos app, nothing to do with
    NetWare. For instance Word Perfect for Dos came with Dos drivers for all
    sorts of printers, one of which was a generic text driver.
    >I wonder: is there a setting in PRINTDEF that could be changed for one
    of the printer configs that would influence the output? Or, would
    PRINTCON apply in this environment?
    Not supplied, AFAICS, but either one of the simpler print drivers
    supplied such as Diablo will do, or you'd need to set one up. Hopefully
    http://www.novell.com/documentation/...a/fm19724.html
    will help you enough as it's been too long since I did it to remember
    the details.
    Andrew C Taubman
    Novell Support Forums Volunteer SysOp
    http://support.novell.com/forums
    (Sorry, support is not provided via e-mail)
    Opinions expressed above are not
    necessarily those of Novell Inc.

Maybe you are looking for

  • How to use TSP with CME9.1 + SIP Phones + EM

    Hi, can anyone explain me how to use the following setup: - Cisco CME 9.1 - IPPhone 8961, 9971, 6921 all connected via SIP - Extension Mobility How can i use the Cisco TSP on my Windows 7 PC to dial via Outlook and so on? Kind regards Andre Lahl

  • Imac will not boot up, chimes with apple logo and beach ball spin??

    imac will not boot up, chimes with apple logo and beach ball spin?? after installing adobe flash and up graded apple softeware

  • [SOLVED] SVNServe + Apache (DAV) error 503 cant commit ONLY php file!

    Hi guys and .. first of all, sorry for my poor english. Here my problem, and i will hope someone can help me go out from this hell!!! Until Yesterday i've used Apache + DAV module + svnserve to host my SVN repository. I've used to commit and update e

  • Finder cant find, usb X'd on start up

    Every start up I lose my usb that goes thru the apple cinema display 21 hub. Reattach and fine.  What gives? Here's the toughie.   Finder window comes up blank for this partition; spinning ball forever.  When I access that volume from here, I can see

  • Cant create smartwifi account

    i cant create smartwifi account becouse of the 2 chapa wordings are too hard for me to read please create accout for me or provide me with solution to remove thw two words