hey guys!!! okay!!! i have a problems that this program is to build to choose a file and the copy it exactly to a new file of my choice but the only is that everytime i do that it happens to make a mistake it copies the file into the new file but instead of copying the same file it happens to copy a numberical value or copies the same thing but ands up putting question marks in between the spaces example is shown below after the source code!!! the problem is between line 28 to 34!!!!

import java.awt.*;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.*;
import java.io.*;

public class ReadWrite
{
public static void main( String args[] ) throws Exception

   {
   
    JFileChooser fc= new JFileChooser();
	if(fc.showOpenDialog(null)==JFileChooser.APPROVE_OPTION)
	{
	  File file= fc.getSelectedFile();
	  Scanner input = new Scanner(file);
	 // JFileChooser fc2= new JFileChooser();
	  fc.showSaveDialog(null);
	  File outfile=fc.getSelectedFile();
	 PrintWriter pr= new PrintWriter(outfile);
	  while(input.hasNext())
	  { String s=input.nextLine();String s2="";
	    for(int i=0; i< s.length();i++)
		      if(  s.charAt(i)!='\n')
			     s2+= s.charAt(i) -100;
			    
	  
	  
	  
	  //  System.out.println(s);
		pr.println(s2);
		}
		input.close();pr.close();
	}
	else
	System.out.println("No file selected");
	}
	}

For Example: file being copied!!!

This is a test
This is another test
you must get ready this time for your test.
If not reading enough you may get F.

AND this is what is being copied!!!

-164515-68515-68-3-681611516
-164515-68515-68-31011164114-681611516
211117-689171516-683116-68141-3021-68164515-6816591-6821114-6821111714-681611516-54
-272-68101116-68141-305103-68110111734-68211117-689-321-683116-68-30-54

Could you please help with these proble thank you!!!!!

Edited 6 Years Ago by peter_budo: Adding code tags

It is pretty hard to understand what you are trying to do, but as a start, you should be using the correct data type. You want characters, not ints (which would explain the numbers you are getting).

You still make little sense, but what is this? why do you subtract 100?

s2+= s.charAt(i) -100;

i'm sorry thats suppose to be s2+=s.charAt(i) + 100!!! the reason being i'm using 16 bit unicode!!!! so what ever is s2 + 100!!!

well basically what i'm trying to do is build a program that takes a file and copies is to another new file identically!!!

The reason you are getting numbers is because you aren't type casting back to 'char'. Try that...

This article has been dead for over six months. Start a new discussion instead.