No installation. USB stick portable applications.
Swiss File Knife

a command line
multi function tool.

remove tabs
list dir sizes
find text
filter lines
find in path
collect text
instant ftp or
http server
file transfer
send text
patch text
patch binary
run own cmd
convert crlf
dup file find
md5 lists
fromto clip
hexdump
split files
list latest
compare dirs
save typing
trace http
echo colors
head & tail
find classes
dep. listing
speed shell
zip search
zip dir list

Depeche View
Source Research
First Steps

firefox add-ons

using vm linux

windows GUI
automation

the d3caster
java game engine

command line
file encryption

free external tools,
zero install effort,
usb stick compliant:

zip and unzip
diff and merge
reformat xml
reformat source

java sources

thread creation

cpp sources

log tracing
mem tracing
hexdump
using printf

articles

embedded
stat. c array
stat. java array
var. c array
var. java array
view all text
as you type
surf over text
find by click
quick copy
multi view
find nearby
fullscreen
bookmarks
find by path
expressions
location jump
skip accents
clip match
filter lines
edit text
highlight
load filter
hotkey list
receive text
send in C++
send in Java
smooth scroll
touch scroll
fly wxWidgets
fly over Qt
search Java

Array Java programming: source code sample for simple Java arrays.

How to read lines of a text file into a very simple fixed size array. Also shows how to sort the array content alphabetically, and how to write array content as another text file.


 
/*
   Java array source code example:
   -  read text file into a simple array
   -  with fixed maximum number of lines
   -  sort the array
   -  write array content into another text file.

   Put this text into a file tmp1.java.
*/

import java.io.*;

public class tmp1
{
   // how many text lines can this program read?
   int MAX_TEXT_LINES = 1000; // up to 1000 lines

   // static start point (no object yet)
   public static void main(String args[]) throws Throwable
      { new tmp1().main2(args); }

   // dynamic start point (on a single object)
   public int main2(String args[]) throws Throwable
   {
      if (args.length < 2)
         return 9+perr("supply in- and output filename.");

      String sInFile  = args[0];
      String sOutFile = args[1];

      // very simple static array for text storage:
      String aTextData[] = new String[MAX_TEXT_LINES+10];
      // +10 are safety spaces, to avoid crash on off-by-one errors.

      int iTextSize = MAX_TEXT_LINES;  // how large is the array
      int iTextUsed = 0;               // how many lines contained

      // read input file into the array.
      BufferedReader fin = new BufferedReader(
         new InputStreamReader(
             new FileInputStream(args[0]), "ISO-8859-1"
             // or US-ASCII,UTF-8,UTF-16BE,UTF-16LE,UTF-16
             ));

      while (true)
      {
         String sLine = fin.readLine();
         if (sLine == null)
            break; // end of file

         // check if array has space for another line
         if (iTextUsed >= iTextSize)
            { perr("overflow: too many text lines\n"); break; }

         aTextData[iTextUsed] = sLine;

         iTextUsed++;
      }

      fin.close();

      // do some processing on the array contents
      processData(aTextData, iTextUsed, iTextSize);

      // write the whole array to output file.
      PrintWriter fout = new PrintWriter(
         new OutputStreamWriter(
             new FileOutputStream(args[1]), "ISO-8859-1"
             ));

      for (int iLine=0; iLine<iTextUsed; iLine++)
      {
         fout.println(aTextData[iLine]);
      }

      fout.close();

      return 0;
   }

   // processing example: sort array text lines alphabetically
   // with the simplest possible sorting algorithm (bubblesort).
   int processData(String aText[], int iLinesUsed, int iLinesAlloced)
   {
      int iOuterIdx, iInnerIdx;

      for (iOuterIdx=0; iOuterIdx<iLinesUsed; iOuterIdx++)
      {
         for (iInnerIdx=iOuterIdx+1; iInnerIdx<iLinesUsed; iInnerIdx++)
         {
            String sLine1 = aText[iOuterIdx];
            String sLine2 = aText[iInnerIdx];

            if (sLine1.compareTo(sLine2) > 0)
            {
               // swap both lines
               aText[iOuterIdx] = sLine2;
               aText[iInnerIdx] = sLine1;
            }
         }
      }

      print("sorted "+iLinesUsed+" lines.\n");

      return 0;
   }

   // alternative processing example: sort using the Arrays class
   int processData2(String aText[], int iLinesUsed, int iLinesAlloced)
   {
      java.util.Arrays.sort(aText, 0, iLinesUsed);
      return 0;
   }

   // helper functions for better readability
   static int perr(String s)
      { System.err.print("error: "+s); return 0; }

   static int print(String s)
      { System.out.print(s); return 0; }
};
// See also: Java example for variable sized array .
 
Download the free Depeche View Lite Text Search Tool