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();
	  File file= fc.getSelectedFile();
	  Scanner input = new Scanner(file);
	 // JFileChooser fc2= new JFileChooser();
	  File outfile=fc.getSelectedFile();
	 PrintWriter pr= new PrintWriter(outfile);
	  { 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);
	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!!!


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

Edited by peter_budo: Adding code tags

8 Years
Discussion Span
Last Post by mabros86

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.