Question

Use python to De-Spanglishification A certain website offers English translations of foreign lyrics. When I search...

Use python to De-Spanglishification A certain website offers English translations of foreign lyrics. When I search for the lyrics to my favorite Latin jam, I get the following result: La Bamba The Bamba Para bailar la Bamba, To dance the Bamba, para bailar la Bamba, to dance the Bamba, se necesita una poca de gracia. one needs a bit of grace. Una poca de gracia para mí, para ti, A bit of grace for me, for you, ya arriba, ya arriba, now come on, come on, These results, which have been stored in the provided file Bamba-Spanglish_v1.txt, contains the Spanish and English lyrics interlaced on odd and even lines. What I really want is a pair of files Bamba-Spanish.txt and Bamba-English.txt which contain the Spanish and English lyrics respectively. Write a program that separates the given file into the two separate files as described.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package filereadwrite;
import java.io.*;

public class FileReadWrite {

public static void main(String[] args) throws Exception {
FileReader readerFile = new FileReader("Bamba-Spanglish_v1.txt");
FileWriter writerSpanish = new FileWriter("Bamba-Spanish.txt");
FileWriter writerEnglish = new FileWriter("Bamba-English.txt");
BufferedReader bufferedReader = new BufferedReader(readerFile);
String line;
int i=0; //will track the odd and even lines
while ((line = bufferedReader.readLine()) != null) {
if(i%2==0){ //if even
writerSpanish.write(line);
writerSpanish.write("\r\n"); //to get to newline
}
else{ //if odd
writerEnglish.write(line);
writerEnglish.write("\r\n");
}
i++;
}
readerFile.close();
writerSpanish.close();
writerEnglish.close();
}
}

Add a comment
Know the answer?
Add Answer to:
Use python to De-Spanglishification A certain website offers English translations of foreign lyrics. When I search...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT