Accessing a file and more.

Hi, I have an encrypted text file. I need to do the following things within my program to make it useful.
1. Read the rather large 3.2MB file.
2. Decrypt the file, it is a simple translation of A = F, B = O etc.
3. Put each word into an ArrayList<String>.
I'm not sure where to start and this has been a bit of a stumbling block for me.

you might find read() useful.
package krc.utilz.io;
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.FileNotFoundException;
* @class: krc.utilz.io.Filez
* A collection of static "file handling" helper methods.
public abstract class Filez
  public static final int BFRSIZE = 4096;
   * reads the given file into one big string
   * @param String filename - the name of the file to read
   * @return the contents filename
  public static String read(String filename)
    throws IOException, FileNotFoundException
    FileReader in = null;
    StringBuffer out = new StringBuffer();
    try {
      in = new FileReader(filename);
      char[] cbuf = new char[BFRSIZE];
      int n = in.read(cbuf, 0, BFRSIZE);
      while(n > 0) {
        out.append(cbuf);
        n = in.read(cbuf, 0, BFRSIZE);
    } finally {
      if(in!=null)in.close();
    return out.toString();
  * a pseudonym for read especially for perl programmers
  public static String slurp(String filename)
    throws IOException, FileNotFoundException
    return(Filez.read(filename));
   * (re)writes the given content to the given filename
   * @param String content - the new contents of the fil
   * @param String filename - the name of the file to write.
  public static void write(String content, String filename)
    throws IOException
    PrintWriter out = null;
    try {
      out = new PrintWriter(new FileWriter(filename));
      out.write(content);
    } finally {
      if(out!=null)out.close();
  * a pseudonym for write especially for perl programmers
  public static void splooge(String content, String filename)
    throws IOException, FileNotFoundException
    Filez.write(content, filename);
   * reads each line of the given file into an array of strings.
   * @param String filename - the name of the file to read
   * @return a fixed length array of strings containing file contents.
  public  static String[] readArray(String filename)
    throws IOException, FileNotFoundException
    return readList(filename).toArray(new String[0]);
   * reads each line of the given file into an ArrayList of strings.
   * @param String filename - the name of the file to read
   * @return an ArrayList of strings containing file contents.
  public static ArrayList<String> readArrayList(String filename)
    throws IOException, FileNotFoundException
    return (ArrayList<String>)readList(filename);
   * reads each line of the given file into a List of strings.
   * @param String filename - the name of the file to read
   * @return an List handle ArrayList of strings containing file contents.
  public static List<String> readList(String filename)
    throws IOException, FileNotFoundException
    BufferedReader in = null;
    List<String> out = new ArrayList<String>();
    try {
      in = new BufferedReader(new FileReader(filename));
      String line = null;
      while ( (line = in.readLine()) != null ) {
          out.add(line);
    } finally {
      if(in!=null)in.close();
    return out;
   * reads the whole of the given file into an array of bytes.
   * @param String filename - the name of the file to read
   * @return an array of bytes containing the file contents.
  public static byte[] readBytes(String filename)
    throws IOException, FileNotFoundException
    return( readBytes(new File(filename)) );
   * reads the whole of the given file into an array of bytes.
   * @param File file - the file to read
   * @return an array of bytes containing the file contents.
  public static byte[] readBytes(File file)
    throws IOException, FileNotFoundException
    byte[] out = null;
    InputStream in = null;
    try {
      in = new FileInputStream(file);
      out = new byte[(int)file.length()];
      int size = in.read(out);
    } finally {
      if(in!=null)in.close();
    return out;
   * do files A & B have the same contents
   * @param String filenameA - the first file to compare
   * @param String filenameA - the second file to compare
   * @return boolean do-these-two-files-have-the-same-contents?
  public static boolean isSame(String filenameA, String filenameB)
    throws IOException, FileNotFoundException
    File fileA = new File(filenameA);
    File fileB = new File(filenameB);
    //check for same physical file
    if( fileA.equals(fileB) ) return(true);
    //compare sizes
    if( fileA.length() != fileB.length() ) return(false);
    //compare contents (buffer by buffer)
    boolean same=true;
    InputStream inA = null;
    InputStream inB = null;
    try {
      inA = new FileInputStream(fileA);
      inB = new FileInputStream(fileB);
      byte[] bfrA = new byte[BFRSIZE];
      byte[] bfrB = new byte[BFRSIZE];
      int sizeA=0, sizeB=0;
      do {
        sizeA = inA.read(bfrA);
        sizeB = inA.read(bfrB);
        if ( sizeA != sizeB ) {
          same=false;
        } else if ( sizeA == 0 ) {
          //do nothing
        } else if ( !Arrays.equals(bfrA,bfrB) ) {
          same=false;
      } while (same && sizeA != -1);
    } finally {
      if(inA!=null)inA.close();
      if(inB!=null)inB.close();
    return(same);
   * checks the given filename exists and is readable
   * @param String filename = the name of the file to "open".
   * @param OPTIONAl String type = a short name for the file used to identify
   *  the file in any exception messages.
   *  For example: "input", "input data", "DTD", "XML", or whatever.
   * @return a File object for the given filename.
   * @throw FileNotFoundException if the given file does not exist.
   * @throw IOException if the given file is unreadable (usually permits).
  public static File open(String filename)
    throws FileNotFoundException, IOException
    return(open(filename,"input"));
  public static File open(String filename, String type)
    throws FileNotFoundException, IOException
    File file = new File(filename);
    String fullname = file.getCanonicalPath();
    if(!file.exists()) throw new FileNotFoundException(type+" file does not exist: "+fullname);
    if(!file.canRead()) throw new IOException(type+" file is not readable: "+fullname);
    return(file);
   * gets the filename-only portion of a canonical-filename, with or without
   * the extension.
   * @param String path - the full name of the file.
   * OPTIONAL @param boolean cutExtension - if true then remove any .ext
   * @return String the filename-only (with or without extension)
  public static String basename(String path) {
    return(basename(path,false));
  public static String basename(String path, boolean cutExtension)
    String fname = (new File(path)).getName();
    if (cutExtension) {
      int i = fname.lastIndexOf(".");
      if(i>0) fname = fname.substring(0,i);
    return(fname);
   * gets the directory portion of a canonical-filename
   * @param String path - the full name of the file.
   * @return String the parent directory of the given path.
  public static String dirname(String path)
    return( new File(path).getParent() );
   * close these "streams"
   * @param Closeable... "streams" to close.
  public static void close(Closeable... streams) {
    for(Closeable stream : streams) {
      if(stream==null) continue;
      try {
        stream.close();
      } catch (Exception e) {
        System.err.println(e);
}

Similar Messages

  • Windows 7 computers asking for network password to access shared files and printers on Windows XP PRO computer.

    I have a network of 10 computers configured as peer-to-peer work group. I have upgraded one of the ten from Windows XP PRO to Windows 7 PRO. The other nine computers are all running XP PRO. AS near as I can tell they are all configured the same. I have the
    same user and same passwords on all computers. One of XP computers is used as a print server. The Windows 7 computer initially was able to access shared files and printers on all XP machines with out requesting a network password.
    Suddenly, the Win 7 computer began requesting a network password to access the shared files and printers on the XP print server. It will not accept any of the user names or passwords (all administrators on both machines with identical names and passwords.)
    The Win 7 computer has no problem accessing the shared files on the other XP machines. It can even access shared printers in a different work group. Apparently something has changed but I'm at my wits end trying to figure what changed on either the Windows
    7 machine or the print server XP machine.
    I would appreciate any help. Thank you

    Hi,
    Based on my research, I would like to suggest the following:
    1.   
    Disable simple file sharing on the Windows XP computer:
    How to disable simple file sharing and how to set
    permissions on a shared folder in Windows XP
    2.   
    On the Windows 7 computer, go to “Control Panel\All Control Panel Items\Network and Sharing Center\Advanced sharing settings” and ensure that the
    following items are turned ON:
    Network Discovery
    File and printer sharing
    And this one is OFF:
    Password protected sharing
    3.   
    Temporarily disable or remove all the security software (firewall, anti-virus, anti-spyware, etc.) on the computers and check if it works.
    In addition,
    I would like to share the following with you for your reference:
    Troubleshoot file and printer
    sharing
    Hope this helps. Thanks.
    Nicholas Li - MSFT

  • Auditing failed access to files and folders in Windows Storage Server 2008 R2

    Hello,
    I've been trying to figure out why I cannot audit the failed access to files and folders on my server.  I'm trying to replace a unix-based NAS with a Windows Storage Server 2008 R2 solution so I can use my current audit tools (the 'nix NAS
    has basically none).  I'm looking for a solution for a small remote office with 5-10 users and am looking at Windows Storage Server 2008 R2 (no props yet, but on a Buffalo appliance).  I specifically need to audit the failure of a user to access
    folders and files they are not supposed to view, but on this appliance it never shows.  I have:
    Enabled audit Object access for File system, File share and Detailed file share
    Set the security of the top-level share to everyone full control
    Used NTFS file permissions to set who can/cannot see particular folders
    On those folders (and letting those permissions flow down) I've set the auditing tab to "Fail - Everyone - Full Control - This folder, subfolders and files"
    On the audit log I only see "Audit Success" messages for items like "A network share object was checked to see whether client can be granted desired access (Event 5145) - but never a failure audit (because this user was not allowed access by NTFS permissions).
    I've done this successfully with Windows Server 2008 R2 x64 w/SP1 and am wondering if anybody has tried this with the Windows Storage Server version (with success of course).  My customer wants an inexpensive "appliance" and I thought this new
    variant of 2008 was the ticket, but I can't if it won't provide this audit.
    Any thoughts? Any of you have luck with this?  I am (due to the fact I bought this appliance out of my own pocket) using the WSS "Workgroup" flavor and am wondering if this feature has been stripped from the workgroup edition of WSS.
    TIA,
    --Jeffrey

    Hi Jeffrey,
    The steps to setup Audit on a WSS system should be the same as a standard version of Windows Server. So please redo the steps listed below to see if issue still exists:
    Enabling file auditing is a 2-step process.
    [1] Configure "audit object access" in AD Group Policy or on the server's local GPO. This setting is located under Computer Configuration-->Windows Settings-->Security Settings-->Local Policies-->Audit Policies. Enable success/failure auditing
    for "Audit object access."
    [2] Configure an audit entry on the specific folder(s) that you wish to audit. Right-click on the folder-->Properties-->Advanced. From the Auditing tab, click Add, then enter the users/groups whom you wish to audit and what actions you wish to audit
    - auditing Full Control will create an audit entry every time anyone opens/changes/closes/deletes a file, or you can just audit for Delete operations.
    A similar thread:
    http://social.technet.microsoft.com/Forums/en-US/winserverfiles/thread/da689e43-d51d-4005-bc48-26d3c387e859
    TechNet Subscriber Support in forum |If you have any feedback on our support, please contact [email protected]

  • I like the idea of auto back-up for my new iMac, Ipad and PC Netbook, particularly if I can access all files and data stored on any device.  But I have a Conceptronic router.  Will Time Capsule work with this and how?

    I like the idea of auto back-up for my new iMac, Ipad and PC Netbook, particularly if I can access all files and data stored on any device.  But I have a Conceptronic router.
    1. Will Time Capsule work with this and how?
    2. Can my printer USB be plugged in and then shared between the devices?
    3. Can I create a network and how?
    4.  What happend when a visitor logs onto my existing wireless router?
    I'm new to Macs (well a returning user having started with Mac Plus!!) and not very technical.  Any help / advice will be much appreciated.
    Ray

    The key to what you seem to want to do is to be able to get Apple's Time Capsule router to "join" the network that your Conceptronic router.  I believe that works with some third-party routers, but I've never seen a list of those that work in such a configuration and I have no experience with Conceptronic equipment.
    You might be better off with a Network-Attached Storage (NAS) device instead of a Time Capsule.

  • There was a problem connecting to the server "my server.local" this file is available on your computer. Access the files and volumes locally.

    Hi,
    I have a strange problem connecting one of the office laptops (Macbook Pro 10.7) to the disk in the Apple Time Capsule.  It's just one laptop that has this problem and the other 3 no problems at all and they all run OS X 10.7 Lion, I can access the Time Capsule disk over WAN on all machines but locally on the problem machine i get this message "There was a problem connecting to the server "myserver.local" this file is available on your computer. Access the files and volumes locally."   Now from this message it sounds like the problem laptop thinks the network drive (Time Capsule) is the same as it's self in the way of name or address however they clearly have different IP addresses locally.   
    Any ideas on this would be apreciated as I can only think a clean install but don't want to do this if not necessary.
    Thanks
    Jarrah

    I think I gave you some bad info in the above, where i enterered the text "myserver.local" & "example.local" this was the host name of the server (Time Capsule) so not local on the computer.
    No i didn't try your method, I'll give it a go - I thought the folder option was for local files and not on a server ?

  • Accessing a file and reading its contents.

    Hi all,
    I created a Portal Application to access a file and display its contents in an iView .
    But it showing the exception like "File Not Found".
    In simple java application i could able to get the result. In portal application i couldn't .
    I have given the full path of the file location.
    I need a help regarding this?
    Regards,
    Eben

    IS the file on the portal server? It must be visible to the service user that runs the Java engine...

  • I'm about to transfer the contents of my existing HDD in my (dead PSU) iMac to another computer. I'm just wanting to know if and how I will be able to access my files and documents from the old hard drive once I've made the backup?

    I'm about to transfer the contents of my existing HDD in my (dead PSU) iMac to another computer. I'm just wanting to know if and how I will be able to access my files and documents from the old hard drive once I've made the backup?

    You are not going to be able to run your old system from the backup on this old computer as the hardware is incompatible.
    You need to get a new computer or a refurbished one.

  • Linked Server to MS Access mdb file and exclusivity??

    I've got an SQL database running on SQL Server 2008.  From this server, I have a linked server to an Access database (access 2003).
    In my database I have a stored procedure that I want to query the access database (linked server) and insert / update some rows in one of my SQL tables.
    The linked server is setup without an ODBC DSN (though, I have tried it with one and still get the same results). 
    When I run the stored procedure RDP'd onto the sql server, it runs without issue.  When I run the stored procedure from management studio from my machine, I get "It is already opened exclusively by another user, or you need permission to view its
    data"
    Unfortunately, this access mdb file is pulled from all over our organizatoin - a sin from a long time ago - but I do know that in both instances, the file is still in use by others.
    My SQL Server and file server where the MDB file exists are both a member of the same domain.  Also, the account the SQL Service runs under is a domain account as well.  
    Does this make any sense?
    Thanks
    sb

    Hi kumar,
    According to your description, when you create an linked server in SQL Server 64 bit to connect to the Access database 32bit , usually, the error 7399 and 7350 will occur. As other post, you need to install SQL Server 32bit. Or you can uninstall 32bit office
    products and install 64bit Microsoft Access Database Engine. For creating Linked Server, if you run on a 64bit environment we need to download
    Microsoft Access Database Engine 2010 Redistributable from Microsoft and install suitable version of software on the machine.
    For more information, see:
    http://calyansql.blogspot.jp/2013/02/fix-cannot-initialize-data-source.html
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Accessing audio file directories more easily

    Is there a way to access audio files like foley or music files more easily. Currently I locate files in the finder and drag into the FCP browser window, but would like to have a way to see the various folders in one place. Is this doable, or is there a better way to do this?

    Meg The Dog wrote:
    Hi =
    At the finder level, just use QuickLook.
    Select the file. Press the spacebar. If is is an audio file it will play, an image it will display, or a movie it will play as well.
    You can use this to sample your files and preselect and screen those you want to drag into the FCP browser.
    MtD
    Thanks for the feedback. I had hoped there was a way FCP could allow adding folders like Motion's file browser. I know I can add the four or five folders (where I have audio content of interest) to the Finder's Places Sidebar, and sample the audio as you said, but hoped there was a way to do this from within FCP file browser, or access via a right mouse click. I am setting up a Macbook as a mobile editing station, so had hoped there was a way to view and select content without having another window (finder) up. It's less cumbersome of a process with a single monitor system.

  • Accessing CVS files and sorting

    Hi
    I'm working on a small program that will basicly allow me to access a cvs file of statistics and analyse it sorting it into the numbers that appear the most often.
    So far i have been able to create the GUI and the FileDialog function allowing the user to choose their cvs file and then its directory is displated in a text area.
    My question is: how do i get the program to access that particular file which has been selected and then begin sorting. Having looked into this i have the option of either choosing an ArrayList, Vectors or something called a 'StringTokenizer' which im not sure as to what it is.
    i would appreciate any help you can offer, as ive been banging my head against the computer all week trying to figour this out.
    Thanx

    Well, i think i've got that FileChooser thing down. At the click of a button you get a dialog box that opens allowing you to select whatever file you want from your computer.
    As for the array; which do you think would be more appropriate
    double [] lotto = new double [48];or
    double [] lotto = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
                   11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
                   21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
                   31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
                   41, 42, 43, 44, 45, 46, 47, 48, 49};The only processing i need to do is find out which of these numbers occurs the most through out that file. Its supposed to be a lottery result analysis program; with the use of a CSV file that contains all the results from previous draws i just need to get the program to select the file (which ive done with the FileChooser) and then searching through it finding the 6 most occuring numbers.
    Its supposed to get me a better understanding of number crunching and number storing.

  • Installed OS X Server, lost access to files and programs. Need to regain access but unsure how?

    I have just installed OS X Server. I have shut the Computer down overnight and on restart has removed my access, personal settings and access to all my programs and file. I have checked the size of the hard drive, it appears all files are still present? Under settings I am still listed as a administrator, I have accessed 'Applications' and opened OS X Server. My Access is still Administrator but I don't know how to return my profile to have access to all files and restor my desktop and settings.
    I someone could help that would be fabulous.

    Safe to presume you didn't make a cloned backup of your system prior to installing the software?
    At this point it is difficult to tell what original settings are left. Why not do the Time Machine restore?

  • I get unwanted Custom Access on files and cannot remove them.

    Since I installed Snow on my iMac quad core, with 10.6.7 at present, I get irregular custom access permissions applied to files and cannot remove some of them. I have tried Tinker Tools System and sometimes that works and other times it does not.
    I have wiped my hard drive clean and zeroed it and reinstalled the system many times and it seems to make no difference.
    The latest occurance was my users folder had custom access applied to it for no obvious reason. I was able to remove it from the user folder but not able to remove it from my home folder.
    I have worked with Dr. Howard Oakley from Mac User magazine and he was unablr to solve my problem also. He has helped me on others with great success.
    HELP!!!!

    Are you using a machine with only one account (which then of course is the account with administrator authority)?  Rather than completely rebuilding the system, did you use Disk Utility to Repair Disk Permissions?
    To repair permissions, boot from the Install DVD while holding down the ‘C’ key. 
    Select your Language preference and when the OS Install screen appears, go to the Tools menu in the Apple menu at the top of the screen and select Disk Utility. 
    From there click on First Aid and then run Repair Disk Permissions a few times in succession.  There will be some error or warning messages left, but they usually can be ignored. 
    Did that help?

  • Unable to opn FLV files and more with newest Quicktime vs 7 Pro

    Hi and thanks in advance -
    Suddenly I cannot open FLV files and I have the Flip4Mac etc plugins. NO LUCK. This is a waste of money patience and time ... or does anyone know of a way to create harmony in the cacophanous quicktime wannabe world. I have a new macbook which I adore and I am ready to throw it down the loo.
    PLEASE help. It's much appreciated.
    Sandy
    macbook dual core intel os 10.4.9   Mac OS X (10.4.9)  

    FLV is Flash Video. QuickTime isn't used (normally)
    to view them and most of use use the free Flash
    Player and its browser plug-in.
    The free Perian http://perian.org/ component may help
    you.
    hi and many thanks for the advise - stupid of me not to see that the flv = flash. I have had the perian plugin installed and running 100 percent for some time.
    I'll give it another go nonetheless and again thanks for the input! BTW the flash player has been running fine too. Perhaps a conflict?

  • Accessing client files and is there any a folder dialog

    The client will provide a directory path in a text box of the some UIX page. The application which is stored in the server has to access the all the files in that directory. What if that directory doesnt has the acess permission to the server.
    One more query:
    Like file dialog is there any component in the UIX to select a perticular folder/directoy
    Regards
    Pradeep

    Try spotlight.   If you have it, EasyFind is an excellent free app from the app store.  Just feed in the file names and all will be revealed.

  • How do I give team members access to Files and Apps in CC for Teams?

    I have 2 seats, myself and a coworker.  Coworker cannot see the files I have stored.  How do I manage file access or assign apps?

    Hi Josh,
    You would have to share files with the process described at the bottom of this document:
    http://helpx.adobe.com/creative-cloud/help/sync-files.html
    -Dave

Maybe you are looking for

  • Auto Claim Tasks in BPM Human Workflow

    All, I have a requirement with a customer to auto claim tasks. When a user selects a task from their task list (tasks by default are assigned to a role), it should be auto claimed. This is to prevent other users from working the task at the same time

  • How to configure JSTL for Jdev9.0.3.1035

    I have added the following .tld files to all the WEB-INF directories: .#sql.tld.1, c, c-rt, fmt, fmt-rt, permittedTaglibs, scriptfree, sql, sql-rt, x, and x-rt. I have added the following .jar files to all the WEB-INF/lib directories: jaxen-full and

  • Opening files in adobe

    How to open file in adobe from safari

  • Canon MG5250 wireless printing

    I have a canon MG5250 and since changing to BT Infinity I have been unable to print wirelessly.  I have assigned the printer a static IP address outside of the DHCP range.  I have entered the passkey on the printer and it has connected to the BT Home

  • How can I tell if I have key logger on my Mac

    I am not computer savy but I have reason to believe that someone has loaded a key logger program on my computer.  Can someone walk me, very patiently, through the steps to find out?