Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: WHY AM I HAVING TO PUT THE ENTIRE FILE PATH?!?!

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default WHY AM I HAVING TO PUT THE ENTIRE FILE PATH?!?!

    Ok im using netbeans and everytime i try input a file or anything i have to put the whole file path...which means none of my programs will be universal. example:

    File file = new File("mgmt.jpg");

    doesn't work...ever. even when mgmt.jpg is in netbeans in my project folder in my list of files under my java package.

    File file = new File("C:/Users/Cameron Hussey/Documents/NetBeansProjects/pic2text/src/pic2text/mgmt.jpg");

    i have to put this...which means noone can use my project.

    why is this happening? this is something that shouldn't even be a problem , that noone should ever have to post on a forum about. but apparantly i do...any ideas guys? here is my whole code...it's a picture2text converter.

    package pic2text;
     
    import java.io.*;
    import java.awt.*;
    import javax.imageio.ImageIO;
    import java.awt.image.BufferedImage;
     
    public class pic2text {
     
        public static void main(String args[]) throws IOException {
            BufferedImage image = null;
     
            File file = new File("mgmt.jpg");
     
            if (file.exists()) {
                image = ImageIO.read(file);
            } else {
                System.out.println("doesn't exist man");
            }
     
            int w;
            int h;
            int clr = 0;
            String xline = null;
            String chars = null;
     
            for (h = 0; h < image.getHeight(); h+=2) {
     
                //System.out.println(clr);
     
                for (w = 0; w < image.getWidth(); w+=2) {
     
                    clr = image.getRGB(w, h);
     
                    switch (clr / -1350000) {
                        case 0:
                            chars = "$";
                            break;
                        case 1:
                            chars = "$";
                            break;
                        case 2:
                            chars = "@";
                            break;
                        case 3:
                            chars = "@";
                            break;
                        case 4:
                            chars = "%";
                            break;
                        case 5:
                            chars = "%";
                            break;
                        case 6:
                            chars = "H";
                            break;
                        case 7:
                            chars = "#";
                            break;
                        case 8:
                            chars = "#";
                            break;
                        case 9:
                            chars = "*";
                            break;
                        case 10:
                            chars = "*";
                            break;
                        case 11:
                            chars = "+";
                            break;
                        case 12:
                            chars = "+";
                            break;
                        case 13:
                            chars = "-";
                            break;
                        case 14:
                            chars = "-";
                            break;
                        case 15:
                            chars = ".";
                            break;
                        case 16:
                            chars = ".";
                            break;
     
                    }
     
                    xline = xline + chars;
     
                }
     
                System.out.println(xline);
                xline = null;
            }
     
        }
    }


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: WHY AM I HAVING TO PUT THE ENTIRE FILE PATH?!?!

    The JVM has a 'current working directory' which is something other than you believe it to be. Search online for pages about it. There'll be a lot. My first guess at how to find out what it is is to instantiate your File object new File("whatever.mpg"), and then use File.getAbsolutePath() to tell you where Java thinks that file should be located.

Similar Threads

  1. [SOLVED] Send File (path) as argument to method
    By efluvio in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 31st, 2011, 01:13 PM
  2. Relative path issue with Context path struts
    By chinnu in forum Web Frameworks
    Replies: 1
    Last Post: March 31st, 2011, 10:17 AM
  3. locating the path to a jar file within a program
    By nemo in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 2nd, 2011, 04:41 PM
  4. Reading in entire contents of text file to one string
    By fortune2k in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: December 12th, 2010, 06:03 PM
  5. Making computer independent file path
    By Javabeginner in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: September 2nd, 2010, 03:56 PM

Tags for this Thread