THis program is suppose to read a txt file, contating text with weird spaces( the space on the space bar, character space on keyboard wtv u want to call it).also write the number of spaces in front of each line, and you are suppose to get rid of them like so:

For example:

Before:

// A short example file
private double singleTax ()
{
if (income <= 27050.0)
return (income * 0.15);
else if (income <= 65550.0)
return (4057.5 + (0.275 * (income - 27050.0)));
else if (income <= 136750.0)
return (14645.0 + (0.305 * (income - 65550.0)));
else if (income <= 297350.0)
return (36361.0 + (0.355 * (income - 136750.0)));
else
return (93374.0 + (0.391 * (income - 297350.0)));
}


After:

0 // A short example file
0
0 private double singleTax ()
0 {
4 if (income <= 27050.0)
8 return (income * 0.15);
4 else if (income <= 65550.0)
8 return (4057.5 + (0.275 * (income - 27050.0)));
4 else if (income <= 136750.0)
8 return (14645.0 + (0.305 * (income - 65550.0)));
4 else if (income <= 297350.0)
8 return (36361.0 + (0.355 * (income - 136750.0)));
4 else
8 return (93374.0 + (0.391 * (income - 297350.0)));
0 }


I used 2 Java files for this so ya: somehow i get a weird error i cant fix so please help thank you.

Squeeze.java

import java.util.Scanner;
import java.io.*;

/**
   A class to compress text data.

   @author  TODO Your Name
   @version TODO Date

   Period - TODO Your Period
   Assignment - A13_3Squeeze

   Sources - TODO list collaborators
 */
public class Squeeze
{
   int reading;
   int writing;
   
   public Squeeze( String fileName )
   {
    
   
      
      
      
      // TODO complete constructor
      // this is the scanner file f is where the file is stored and
      //3rd line is reading f
      Scanner in;
      try
      {
        in = new Scanner(new File("squeeze.txt"));
        String test =in.nextLine();
        //
        while(  in.hasNext())
        {
          System.out.println(in.next());
        }

        System.out.println(test);
      }
      catch(IOException i)
      {
        System.out.println("Error: " + i.getMessage()); 
        
      }
      
      FileWriter out;
      try
      {
         String one = " #hello!!!";
         out = new FileWriter("squeeze.txt");
        out.write(one, 0, one.length());
        out.close();
      }
      catch(IOException i)
      {
        System.out.println("Error: " + i.getMessage());
      }

   
   }
      
      //writing i guess
      
     

   public void doSqueeze(String str1, FileOutput outFile)
   {
      // TODO complete method
     int i = 0;
     char ch;
     
     int numberOfSpaces = 0;
     while(str1.charAt(i)==' ')
     {
       i++;
       numberOfSpaces++;
       
       
     }
     outFile.print(i + " ");
     String str2 = str1.substring(i);
     outFile.println(str2);
     
     numberOfSpaces = i;
     
     
   }
   public void readFile()
   {
      FileInput inFile;
      int linecount = 0;
      String fileName = " squeeze.txt";
      String number;
      
      FileOutput outFile;
      String outfileName = "squeeze1.txt";
      outFile = new FileOutput(outfileName);
      inFile = new FileInput(fileName);
      
      number = inFile.nextLine();
      removeSpaces(number, outFile);
      while(inFile.hasNextFile()) {
         number = inFile.nextLine();
         removeSpaces(number, outFile);
         linecount++;
      }
      outFile.close();
        
     }
      
   
   
   }

// TODO attach output

SqueezeTester.java

public class SqueezeTester
{
   /**
      TODO Write your method description here.
      @param args command-line arguments (not used)
    */
   public static void main( String[] args )
   {
      // TODO complete test method
     //reading the file 
    Squeeze shit = new Squeeze("squeeze.txt");
   shit.readFile();
   
   }
}

What error? We cannot play both compiler and JVM here to try and figure out what the error was, and where it is, so please help us out and post the complete error message, preferably with stacktrace.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.